- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are default arguments in python?
Python allows function arguments to have default values; if the function is called without the argument, the argument gets its default value
Default arguments:
Example
Python has a different way of representing syntax and default values for function arguments. Default values indicate that the function argument will take that value if no argument value is passed during function call. The default value is assigned by using assignment (=) operator. Below is a typical syntax for default argument. Here, foo parameter has a default value Hi!
def defaultArg(name, foo='Come here!'): print name,foo defaultArg('Joe')
Output
Joe Come here!
We see that in the above code there is one required argument and one default one in the declaration. In the output we see that both the arguments are printed even though only one argument was passed in the function call. The default argument is passed automatically and appears in the output of the function call.