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 Functions and Looping Functions

Structural Difference of Functions?

What is the difference between the way this two functions are working.:

praise.upper() and len(praise)

I don't understand the structure which they are following. praise.upper() - On the first one you are assigning the functions with .upper

Len(praise) - One the second one you are using () where you are entering the variable inside?

1 Answer

Steven Parker
Steven Parker
215,940 Points

The first one is a method. That's a special kind of function that is also an object member. It can only be accessed using the membership operator (the period) on an object of the correct class. I assume "praise" is a string, since "upper" is a common method of strings. A method might take arguments in the parentheses, but they don't need to if they only act directly on the object they are called on.

The second form is an ordinary function. It can be accessed anywhere, and any values it needs are passed as arguments inside the parentheses.