This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)
You can set parameters and arguments for a function as shown below:
Parameters:
*Memos:
- A parameter can have a default value.
- All the parameters after the parameter which has a default value must have default values.
- A function cannot have multiple same name parameters.
def func(fname, lname, age, gender): pass
def func(fname="John", lname="Smith", age=36, gender="Male"): pass
def func(fname, lname, age=36, gender="Male"): pass
def func(fname="John", lname="Smith", 36, "Male"): pass
# SyntaxError: invalid syntax
def func(fname, lname, age, gender, lname): pass
# SyntaxError: duplicate argument 'lname' in function definition
Arguments:
*Memos:
- An argument can have a keyword.
- All the arguments after the argument which has a keyword must have keywords.
- There cannot be multiple same name arguments
def func(fname, lname, age, gender):
print(fname, lname, age, gender)
func("John", "Smith", 36, "Male")
func(fname="John", lname="Smith", age=36, gender="Male")
func(age=36, lname="Smith", gender="Male", fname="John")
func("John", "Smith", age=36, gender="Male")
# John Smith 36 Male
func(fname="John", lname="Smith", 36, "Male")
# SyntaxError: positional argument follows keyword argument
func(36, "Smith", age=36, fname="John")
# TypeError: func() got multiple values for argument 'fname'
func(lname="Smith", lname="Brown", age=36, gender="Male")
# SyntaxError: keyword argument repeated: lname
def func(fname="John", lname="Smith", age=36, gender="Male"):
print(fname, lname, age, gender)
func()
# John Smith 36 Male
func("Tom", "Brown")
# Tom Brown 36 Male
func(gender="Female", fname="Anna")
# Anna Smith 36 Female
This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
Super Kai (Kazuya Ito) | Sciencx (2025-05-04T12:41:28+00:00) Parameters & Arguments in Python. Retrieved from https://www.scien.cx/2025/05/04/parameters-arguments-in-python/
" » Parameters & Arguments in Python." Super Kai (Kazuya Ito) | Sciencx - Sunday May 4, 2025, https://www.scien.cx/2025/05/04/parameters-arguments-in-python/
HARVARDSuper Kai (Kazuya Ito) | Sciencx Sunday May 4, 2025 » Parameters & Arguments in Python., viewed ,<https://www.scien.cx/2025/05/04/parameters-arguments-in-python/>
VANCOUVERSuper Kai (Kazuya Ito) | Sciencx - » Parameters & Arguments in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/05/04/parameters-arguments-in-python/
CHICAGO" » Parameters & Arguments in Python." Super Kai (Kazuya Ito) | Sciencx - Accessed . https://www.scien.cx/2025/05/04/parameters-arguments-in-python/
IEEE" » Parameters & Arguments in Python." Super Kai (Kazuya Ito) | Sciencx [Online]. Available: https://www.scien.cx/2025/05/04/parameters-arguments-in-python/. [Accessed: ]
rf:citation » Parameters & Arguments in Python | Super Kai (Kazuya Ito) | Sciencx | https://www.scien.cx/2025/05/04/parameters-arguments-in-python/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.