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
Filename = readme.pdf, Flag = False, number = 4
Was this helpful?
Similar Posts
- Function argument unpacking in Python
- Add column to existing table with default value SQLAlchemy
- Insert new column with default value in Pandas DataFrame
- [Python] The get() method on Python dicts and its "default" arg
- [Python] Range - standard function to create a list of numbers
- [Python] Function returns multiple values
- [Python] Function parameters - pack and unpack