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 trialPetko Delchev
Courses Plus Student 2,103 PointsStructural 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
231,248 PointsThe 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.