25
loading...
This website collects cookies to deliver better user experience
variable_name : data_type
.name : str = 'Rohan'`
age : int = 19
def function_name(argument_1 : data_type,argument_2 : data_type) -> return_type:
function body
def sum(num_1 : int,num_2 : int = 3) -> int: # here 3 is the default value for the argument num_2
return num_1 + num_2
function_name.__annotations__
i.e.:def sum(num_1 : int,num_2 : int = 2) -> int:
return num_1 + num_2
sum.__annotations__ # accessing the __annotations__ attribute of the function
{'num_1': <class 'int'>, 'num_2': <class 'int'>, 'return': <class 'int'>}
def sum(num_1 : int,num_2 : int = 2) -> int:
'''
A function that takes two integers as input and returns their sum
'''
return num_1 + num_2
help(sum)
it will result in:sum(num_1: int, num_2: int = 2) -> int
A function that takes two integers as input and returns their sum