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 execute bash commands in Python script?

Leave a Reply

Your email address will not be published.

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