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 trialKurobe Kuro^T_T^
5,369 Pointsi dont get it, is __int__, __float__, __init__, and__name__ names or variavles name or they have they own use??
;-;
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsVariable names with a double-underscore prefix and suffix are typically reserved for built-in Python object attributes and methods and each has a special purpose.
As mentioned in PEP 8:
__double_leading_and_trailing_underscore__
: "magic" objects or attributes that live in user-controlled namespaces. E.g.__init__
,__import__
or__file__
. Never invent such names; only use them as documented.
As for your list:
-
__int__
: name of class method called when class instance issued in an integer context -
__float__
: name of class method called when class instance issued in an float context -
__init__
: name of class method called to initialize a class instance after it has been created -
__name__
: an object attribute containing the string name of the object. see below
>>> def foo():
... pass
...
>>> foo
<function foo at 0x7ffa6241ba60>
>>> f = foo
>>> f
<function foo at 0x7ffa6241ba60>
>>> f.__name__
'foo'
Post back if you need more help. Good luck!!
Kurobe Kuro^T_T^
5,369 PointsKurobe Kuro^T_T^
5,369 Pointsohhh thank you i understand now