I am learning python but I get confused when I see the functions or variables that start with double underscores like:
__getAttributes__ __dict
How can I find all the functions and attributes that start with double underscore so that ? can understand them better?
Use the
dirbuilt- in function. It returns a list of all attributes and methods in a given object. It’s also a great way to quickly discover functionality or recall method names. Example:Those methods are usually used by built-in functions or operators. For example
__eq__tests if two objects are equal and is used by all operators and functions that need to compare values.There are many articles and guides out there for those “magic methods”, such as http://www.rafekettler.com/magicmethods.html .
Edit: also check the comments for great official documentation on those methods. They give a nice overview of everything that is available.