Default Function Parameters in Python

Python

In the example below, if a score isn't provided then the function sets score to be 0.

 1|  def print_score(name,age,score=0):
 2|      print(name,'is',age,'and has score of',score)
 3|  print_score(name='Nadia Watts', age=31)
 4|  print_score(name='Nadia Watts', age=31, score=5)
Did you find this snippet useful?

Sign up for free to to add this to your code library