What is Python Functions | EP-43 Python Functions | Functions in Python | Free Python Tutorials
What is a Python Function?
"""A function in Python is a reusable block of code that performs a specific task.
It takes input values (arguments) and returns an output value (result).
syntax:
def function_name(parameter):
#statment
return expression"""
Creating a Function in Python
def company():
print("welcome to cybrosys")
Calling a Function in Python
def company():
print("welcome to cybrosys","calling a function")
company()
Python Function with Parameters
"""
A parameter in a function is a variable that receives a value when the function is called.
It acts as a placeholder for the actual data that will be used within the function's code.
syntax:
def function_name(parameter: data_type)- return_type:
body of the function
return expression """
def greet(name , greeting):
"""Greets a person with a customized message."""
print(greeting , name)
greet("Alice" , "Hello")
def add(num1:int , num2:int)- int:
" add two numbers"
num3 = num1 + num2
return num3
num1= int(input("enter the num1"))
num2= int(input("enter the num2"))
num3 =add (num1,num2)
print(num3)
Python Function Arguments
"""An argument is the actual value that is passed to a function when it's called.
It replaces the corresponding parameter in the function's body."""
def even_odd(x):
if(x%2==0):
print("Even number")
else:
print("Odd number")
even_odd(5)
even_odd(2)
#PythonFunctions #LearnPython #PythonTutorial #PythonForBeginners #FreePythonTutorial #PythonProgramming #CodingForBeginners #ProgrammingTips #FunctionsInPython #PythonBasics #Python #Programming #Coding #FreeCourse #TechTutorial
Connect With Us:
—————————————
➡️ Website: https://www.cybrosys.com/
➡️ Email: info@cybrosys.com
➡️ Twitter: / cybrosys
➡️ LinkedIn: / cybrosys
➡️ Facebook: / cybrosystechnologies
➡️ Instagram: / cybrosystech
➡️ Pinterest: / cybrosys