December 2018
Beginner to intermediate
796 pages
19h 54m
English
I will start with the simplest class you could ever write in Python:
# oop/simplest.class.pyclass Simplest(): # when empty, the braces are optional passprint(type(Simplest)) # what type is this object?simp = Simplest() # we create an instance of Simplest: simpprint(type(simp)) # what type is simp?# is simp an instance of Simplest?print(type(simp) == Simplest) # There's a better way for this
Let's run the preceding code and explain it line by line:
$ python simplest.class.py<class 'type'><class '__main__.Simplest'>True
The Simplest class I defined has only the pass instruction in its body, which means it doesn't have any custom attributes or methods. Brackets after the name are optional if empty. I will print its ...
Read now
Unlock full access