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 trialAdiv Abramson
6,919 PointsIs there an object of which print() is a method/member of?
In Python, everything is an object. Every object has methods and attributes. Is there some underlying/implied object that functions like print() is a method/member of? Can a function/method exist independently of an object?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsHi Adiv,
In Python, everything is an object.
Correct!
Every object has methods and attributes.
Correct!
Is there some underlying/implied object that functions like print() is a method/member of?
Yes. print()
is one of the built-in functions. If you run type(print)
, you'll see <class 'builtin_function_or_method'
>
Can a function/method exist independently of an object?
No. When you create a function
it is part of the current module. In many cases, the module is the text file containing the function. A method
, is by definition, bound to an object be it a class or class instance.
Does that cover it? Post back for more details, if needed.
Adiv Abramson
6,919 PointsAdiv Abramson
6,919 PointsThank you for your great answer!
So the builtin_function_or_method class is instantiated every time a Python script is run? Could print() be invoked with reference to this class? For example, builtin_function_or_method.print("My string") ? Not that I would want to do that of course! LOL Thanks again.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 Points