Objects



• In Python everything is an object
• Objects (over simplified explanation) are purpose-built groupings of variables (called attributes) and functions (called methods) that work together to do something useful
• To access the attributes (variables) or methods (functions) contained within an object, use "." dot-syntax to do so

>>> a = 57
>>> a.bit_length()              # attribute
6

>>> "WhO wRoTe THIs?".lower()   # method
'who wrote this?'


• To look inside an object and see what names (attributes and methods) are defined inside it, pass the object to the dir(<object>) function






Index