Lecture 6 Program
Lecture 6 Program
programming
Md Nagrul Islam
Lecturer
Department of Computer Science and Mathematics
Mymensingh Engineering College, Mymensingh, Bangladesh
Contents.
Python Functions
Python Functions
Calling a Function
To call a function, use the function name followed
by parenthesis:
Example
def my_function():
print("Hello from a function")
my_function()
Python Functions
Arguments
Information can be passed into functions as arguments.
Arguments are specified after the function name, inside the
parentheses. You can add as many arguments as you want, just
separate them with a comma.
The following example has a function with one argument (fname).
When the function is called, we pass along a first name, which is
used inside the function to print the full name:
Example
def my_function(fname):
print(fname + " Refsnes")
my_function("Emil")
my_function("Tobias")
my_function("Linus")
Recursion
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = 7
factorial = 1