- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Functions / of Python Functions
Functions
Functions are mainly used to do a specific task and which only runs when we called. To create a function in python we use def keyword. There are four types of functions in every programming language. If you know these four types, you can write or learn any programming language easily.
How to create a function in python?
We can create functions by using a def keyword.
Syntax:
def function_name():
#your statements
pass
# How to call a function? def runIt(): print("Factory Running...") runIt()
# Types of functions
- Function with no parameters and no return value
- Function with parameter and no return value
- Function with no parameters and with a return value
- Function with parameters and values
# Function with no parameters and no return value
# Function with no parameters and no return value def runFactory(): print("Factory Running...") runFactory()
# Function with parameter and no return value
# Function with parameter and no return value def runFactory(rawMaterial): print("Factory Running with raw materials like ",rawMaterial) rawMaterial = ["wheels","glass","gearbox","bolts"] runFactory(rawMaterial)
# Function with no parameters and with a return value
# Function with no parameters and with a return value def runFactory(): print("Factory Running with no raw materials") return "Car" product = runFactory() print("Factory gives products like ",product)
# Function with parameters and values
# Function with parameters and values def runFactory(rawMaterial): print("Factory Running with raw materials like ",rawMaterial) return "Car" rawMaterial = ["wheels","glass","gearbox","bolts"] product = runFactory(rawMaterial) print("Factory gives products like ",product)
Note: The default return value of a function is None