Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created September 10, 2018 17:18
Show Gist options
  • Save pknowledge/90a5e87b73d9546800c33ed7dc3a4cce to your computer and use it in GitHub Desktop.
Save pknowledge/90a5e87b73d9546800c33ed7dc3a4cce to your computer and use it in GitHub Desktop.
Default Arguments *args and **kwargs in Python
# Python Tutorial for Beginners - Default Arguments *args and **kwargs in Python
print('----Default Arguments----')
def studentExample1(name='unknown', age=0):
print("name: ", name)
print('age', age)
studentExample1()
studentExample1('tom')
studentExample1('tom', 22)
print('----*args-----')
def studentExample2(name, age, *marks):
print("name: ", name)
print('age', age)
print('marks', marks)
for x in marks:
print(x)
studentExample2('tom', 22, 95, 70, 80, 50)
print('----*kwargs----')
def studentExample3(name, age, **marks):
print("name: ", name)
print('age', age)
print('marks', marks)
for key, value in marks.items():
print(key, ' ', value)
studentExample3('tom', 22, english=95, math=70, physics=80, biology=50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment