Reading 9
Dunder Methods
Used, to enrich Python classes, dunder methods unlock access to powerful language features.
- _init_ - class constructor
- _repr_ - the machine readable “official” string representation of an object
- _str_ - the more readable string version of the object for the end user.
Operator Overloading
Use the following method to introduce comparative operators in class methods:
from functools import total_ordering
@total_ordering
class Account:
# ... (see above)
def __eq__(self, other):
return self.balance == other.balance
def __lt__(self, other):
return self.balance < other.balance
Proobability
Probability is asking, “what is the chance that some event will happen?” With iteration, especially in very large numbers, the statistics collected and the predicted probability merge closer and closer together. This is similar to the law of large numbers.
- Central Limit Theorem - the theory that stastics will reflect probability with more iteration.
- Three Sigma Rule - rule that most of our observations fall within certain ranges of the mean. 1 standard deviation: 68%, 2 standard deviations: 95, and 3 standard deviations: 99.7%
- source: https://i.imgur.com/Mt3RyE0.png