1def my_function(name, age = 20):
2 print(name + " is " + str(age) + " years old"
3
4my_function("Mitro") # Mitro is 20 years old
5my_function("Mitro", 26) #Mitro is 26 years old
1def my_function(num1,num2=0): #if num2 is not given, it will default it to zero
2 return num1 + num2
3
4print(my_function(1,2)) #prints out 3
5print(my_function(4)) #prints out 4 since num2 got defaulted to 0
1class Test:
2 def __init__(self, val, num = 0):
3 self.val = val
4 self.num = num
5
6# you can write this:
7
8t = Test(1)
9print(t.num) # prints 0
10
11# OR this
12
13t = Test(1, 2)
14print(t.num) # prints 2