Ellipsis
Use ... (Ellipsis), an alternative to pass
.
def main():
...
if True:
...
single line return
For single line utility functions use, single line return statement.
def greet(): return "Welcome!"
def todo(): ...
Document Your Functions
To get proper documented Classes or functions with auto-completion define types of parameters and return types
def rectangle_area(l: float, b: float) -> float:
area = l * b
return area
Clever use of type()
method
Call type function to know default value of any datatype.
>>> type(512)()
0
>>> type(True)()
False
Also, Use for type checking
>>> type('Apple') == str
True
>>> type([1, 2, '3']) == list
True
Thanks and Cheers
RajeshJ3