

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Default arguments in Python
A default argument is an argument that assumes a default value if a value is not provided in the function call for that argument. The following example gives an idea on default arguments, it prints default age if it is not passed −
Example
#!/usr/bin/python # Function definition is here def printinfo( name, age = 35 ): "This prints a passed info into this function" print "Name: ", name print "Age ", age return; # Now you can call printinfo function printinfo( age=50, name="miki" ) printinfo( name="miki" )
Output
When the above code is executed, it produces the following result −
Name: miki Age 50 Name: miki Age 35
- Related Questions & Answers
- What are default arguments in python?
- Default Arguments in C++
- Default arguments and virtual function in C++
- Required arguments in Python
- Keyword arguments in Python
- Variable-length arguments in Python
- Command Line Arguments in Python
- How to arguments object with Rest, default, and destructured parameters in JavaScript?
- Packing and Unpacking Arguments in Python?
- Command Line and Variable Arguments in Python?
- How to add command line arguments in Python?
- How to pass arguments by value in Python function?
- How to pass arguments by reference in Python function?
- What are required arguments of a function in python?
- How to handle invalid arguments with argparse in Python?
Advertisements