DEV Community

Rajesh Joshi
Rajesh Joshi

Posted on

Python 🀫 Hidden Syntax 🀫, You'll be using always from now 😝

Ellipsis

Use ... (Ellipsis), an alternative to pass.

def main():
    ...
Enter fullscreen mode Exit fullscreen mode
if True:
    ...
Enter fullscreen mode Exit fullscreen mode

single line return

For single line utility functions use, single line return statement.

def greet(): return "Welcome!"
Enter fullscreen mode Exit fullscreen mode
def todo(): ...
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Python 🀫 Hidden Syntax 🀫, You'll be using always from now 😝

Clever use of type() method

Call type function to know default value of any datatype.

>>> type(512)()
0
>>> type(True)()
False
Enter fullscreen mode Exit fullscreen mode

Also, Use for type checking

>>> type('Apple') == str
True
>>> type([1, 2, '3']) == list
True
Enter fullscreen mode Exit fullscreen mode

Thanks and Cheers
RajeshJ3

Top comments (1)

Collapse
Β 
pinnheads profile image
Utsav Deep β€’

Hey thanks for the info, never new about the ellipsis as an alternative to 'pass' in python.