
- 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
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.
- Related Questions & Answers
- Default arguments in Python
- Default Arguments in C++
- What are required arguments of a function in python?
- What are variable arguments in java?
- Default arguments and virtual function in C++
- What are optional arguments in JavaScript Functions?
- What are Default parameters in JavaScript?
- What are Default Constructors in Java?
- What are wildcards arguments in Generics In Java?
- What are default function parameters in JavaScript?
- What are Default Methods in Java 8?
- What are the default array values in Java?
- Required arguments in Python
- Keyword arguments in Python
- What are default-parameters for function parameters in JavaScript?