December 2017
Beginner
412 pages
10h 8m
English
Any method (or other name) beginning and ending with two underscores is considered special by Python. The help documentation for strings shows these methods, among many others:
| | | Methods defined here: |
| | | |
| | | __add__(self, value, /) |
| | | Return self+value. |
These methods are typically connected with some other syntax in Python: use of that syntax will trigger a method call. For example, string method __add__ is called when anything is added to a string:
| | >>> 'TTA' + 'GGG' |
| | 'TTAGGG' |
| | >>> 'TTA'.__add__('GGG') |
| | 'TTAGGG' |
Programmers almost never call these special methods directly, but it is eye-opening to see this and it may help you to understand how Python works.
Integers and floating-point ...
Read now
Unlock full access