default arguments python typehint code example
Example 1: python default arguments
def my_function(name, age = 20):
print(name + " is " + str(age) + " years old"
my_function("Mitro")
my_function("Mitro", 26)
Example 2: python default arguments
def your_function(arg,kwarg='default'):
return arg + kwarg
Example 3: specify return type python function
def greeting(name: str) -> str:
return 'Hello, {}'.format(name)
Example 4: python optional type annotation
from custom_module import SomeClass
from typing import Optional
class SubClass:
a_reference: Optional[SomeClass]
def __init__(self):
self.a_reference = None