File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ # function :- is a block of code that is executed when it is called
2+ # We make use of 'def' to define a function
3+
4+ # Function Declaration
5+ def hello ():
6+ print ("Hello" )
7+
8+ hello ()
9+
10+ # Function with parameters( also shows function overloading )
11+ def hello ( name ):
12+ print ("Hello " + name )
13+
14+ hello ("aakarsh" )
15+
16+ # Function having varied argument list
17+ def hello ( first_name , last_name , age ):
18+ print ("Hello " + first_name + " " + last_name )
19+ print ("You are " + str (age )+ " years old!" )
20+
21+ hello ("aakarsh" , "mj" , 21 )
22+
Original file line number Diff line number Diff line change 1+ # positional args :- order of arguments matter
2+ # keyword args :- arguments preceded by an identifier( which are names of variables
3+ # in the argument list) when we pass them to function order of arguments do not
4+ # matter,unlike positional arguments python knows the name of arguments which
5+ # it recievers
6+
7+ def hello ( first_name , middle_name , last_name ):
8+ print ("Hello " + first_name + " " + middle_name + " " + last_name )
9+
10+ hello ( "aakarsh" , "m" , "j" ) #positional arguments
11+ hello ( middle_name = "m" , last_name = "j" , first_name = "aakarsh" ) #keyword arguments
12+
Original file line number Diff line number Diff line change 1+ # return statement returns a value to the caller
2+
3+ # Eg - Use with functions
4+ def multiply (operand1 , operand2 ):
5+ return operand1 * operand2
6+
7+ print (multiply (6 ,8 )) #You can store the value in a variable or print it on screen
8+ product = multiply (10 ,5 )
9+ print (product )
You can’t perform that action at this time.
0 commit comments