This content originally appeared on DEV Community and was authored by Rajesh Joshi
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
This content originally appeared on DEV Community and was authored by Rajesh Joshi
Rajesh Joshi | Sciencx (2021-09-13T02:35:25+00:00) Python ? Hidden Syntax ?, You’ll be using always from now ?. Retrieved from https://www.scien.cx/2021/09/13/python-%f0%9f%a4%ab-hidden-syntax-%f0%9f%a4%ab-youll-be-using-always-from-now-%f0%9f%98%9d/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.