python

[Python] Default value of function argument

# Example demonstrates usage of  function arguments default values

def foo(filename='testid', flag = True, number = None):
    pdf_file = filename + ".pdf"
    print(f'\n Filename =  {pdf_file}, Flag = {flag}, number = {number}')


if __name__ == '__main__':
    foo()
    foo("readme", False, 4)
Output
Filename = testid.pdf, Flag = True, number = None

Filename = readme.pdf, Flag = False, number = 4
Was this helpful?