Python Function
Python Functions is a block of statements that return the specific task. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over and over again.
Some Benefits of Using Functions
- Increase Code ReadabilityΒ
- Increase Code Reusability
Python Function Declaration
The syntax to declare a function is:
def my_function():
Β print(“Hello from a function”)
my_function()
Types of Functions in Python
Below are the different types of functions in Python:
Built-in library function: These are Standard functions in Python that are available to use.
User-defined function: We can create our own functions based on our requirements.
Creating a Function in Python
We can define a function in Python, using the def keyword. We can add any type of functionalities and properties to it as we require. By the following example, we can understand how to write a function in Python. In this way we can create Python function definition by using def keyword.
# A simple Python function
def fun():
Β Β print(“Welcome to techdcode”)
Calling a Function in Python
After creating a function in Python we can call it by using the name of the functions Python followed by parenthesis containing parameters of that particular function. Below is the example for calling def function Python.
# A simple Python function
def fun():
print(“Welcome to techdcode”)
# Driver code to call a function
fun()
Output:
Welcome to techdcode
Thank you for taking the time to read this post.I hope you found it helpful!
Social Media Links of Tech DCode
ππ» YouTube
https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
ππ»Instagram
https://www.instagram.com/thetechdcode/
β ππ»Facebook Page
https://www.facebook.com/thetechdcode
ππ»Twitter
ππ»Telegram Channel
https://t.me/thetechdcode
ππ»Tech DCode Linktree
https://linktr.ee/thetechdcode
ππ»My Personal Handles
https://linktr.ee/virtualshivamin
Social Media Links of SHIVAM SINGH (OWNER) :
ππ»Instagram :
https://www.instagram.com/virtualshivamin/
ππ»Facebook Page :
https://www.facebook.com/virtualshivamin/
ππ»Twitter :
https://twitter.com/virtualshivamin/
ππ»Personal Linktree :
https://linktr.ee/virtualshivamin