Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmarkspenser
Courses Plus Student 256 PointsNaming in function methods.
We have seen this: "Hello".rjust(35)
It can be rewritten as: "something".methodOfClass(argument) or "something".function(argument)
I don't know what is "something".
1 Answer
Kenneth Love
Treehouse Guest Teacher"something"
is a string.
markspenser
Courses Plus Student 256 Pointsmarkspenser
Courses Plus Student 256 PointsHeh I know it's a string, but in more general naming structure.
Is it an ARGUMENT too ?
Because when I assume, if that method was not part of str class and would be stand alone function; it would look like: rjust('hello', 35)
Correct ? Thank you Kenneth
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest Teacher"something"
is an instance of thestr
class. The.function()
or.rjust()
is a method that belongs to thestr
class.But, behind the scenes, what's happening is
str.rjust("something", 35)
(which you can call if you want but that's kinda messy). So it's both an instance and an argument.markspenser
Courses Plus Student 256 Pointsmarkspenser
Courses Plus Student 256 PointsSo to understand it and remember it to my brain. We can say this ?: Argument is always something inside of parenthesis. In matter of functions. Like this: print(argument)
Instance is another programming term (also in matter of functions), which is always something before class method. Like this: instance.rjust(35)
Correct ?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherArguments are always inside of parentheses, yes.
And, yes, most of the time (100% of the time so far at Treehouse), the thing before a dot and an instance method (because class methods are a thing and not what we're talking about right now), would be an instance.
Iain Simmons
Treehouse Moderator 32,305 PointsIain Simmons
Treehouse Moderator 32,305 Pointsmarkspenser In regards to your comment
Well an instance is an object of a particular class that has been instantiated. It can't use the class's methods until it has been instantiated.
Also, one example of something coming before the dot and method name being called is where the object calling the method is the class itself, rather than an instance of it (one class can have any number of instances).
And Kenneth Love, one place where it gets a bit tricky is in the Taking The Quiz video in Stage 2 of Dates and Times in Python where you use the following:
Quiz().take_quiz()
I guess that's an object that has been instantiated and calls a method in one statement, without assigning the instance object to another variable... so yes, I guess what you said holds true.
Also, when you import a module, it creates an instance of a module object. That's the other thing you're likely to see placed before the dot and method name.