Python Cheatsheet
Resources
None (null) Checks
# bad
if x != None:
pass
# good
if x is not None:
pass
Incremement / Decrement
No support for pre/post increment operators like i++
i+=1
x-=1
Loops
Assignment in loops
Python 3.8 introduced
while x :=
Classes
Private Variables
Python does not support classic private variables. Use the _
convention to indicate that something is private.
class Person:
__init__(self, name, ssn) -> None:
self.name = name
self._ssn = ssn
Constructors
class Person:
def __init__(self):
# body of the constructor