Python Functions
A Python function is a block of reusable code designed to perform a specific task, which can be called and executed within a program.
def my_function():
print("Hello from a function")
my_function()
Python Online Compiler
Function Parameters
def my_function(fname):
print(fname + " Doe")
my_function("John")
my_function("Jane")
my_function("Leo")
Python Online Compiler
Function with user input
def my_function(name,place,age):
print("Hello I am",name,"from",place,"and I am",age,"years old")
name1 = input("Enter your name: ")
place1 = input("Enter your place: ")
age1 = input("Enter your age: ")
my_function(name1,place1,age1)
Python Online Compiler
Return Values
def my_function(x,y):
z=x*y
return z
print(my_function(3,4))
print(my_function(5,8))
print(my_function(9,7))
Python Online Compiler