Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (Retired) Say Hello to Python Help!

Naming 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

Heh 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
Kenneth Love
Treehouse Guest Teacher

"something" is an instance of the str class. The .function() or .rjust() is a method that belongs to the str 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.

So 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
Kenneth Love
Treehouse Guest Teacher

Arguments 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.

markspenser In regards to your comment

Instance is another programming term (also in matter of functions), which is always something before class method. Like this: instance.rjust(35)

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:


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.