Skip to content

How to set a default parameter in Python?

def my_function(name, age = 20):
  print(name + " is " + str(age) + " years old"

my_function("Mitro") # Mitro is 20 years old
my_function("Mitro", 26) #Mitro is 26 years old
See also  How to set global variable in Python function?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.