Module 4 Python Functions
Module 4 Python Functions
def function():
print(“Happy birthday to you”)
print(“Happy birthday to you”)
print(“Happy birthday to you”)
function()
f-string
Output:
My name is
I’m years old
I live in My contact
Number is:
Example:
To add
def add1(num1, num2):
Print(num1 + num2)
To Subtract
def sub1(num1, num2):
print(num1 – num2)
exercise
Sample_name = lambda a : a + 10
print(Sample_name(5))
Output: 15
TwoV = lambda a, b: a+b
print(TwoV(5,8))
Output: 13
Python Arrays
Arrays are used to store multiple values in one single
variable:
An array is a data structure that lets us hold multiple
values of the same data type. Think of it as a container
that holds a fixed number of the same kind of object.
Python makes coding easier for programmers.
An array is used to store more than one value at a time. It
can hold multiple values in a single variable, and also
helps you reduce the overall size of the code. Arrays save
time.
Creating an Array in Python
EXAMPLE:
Code:
Foods = [“Salad”, “Fried Chicken”, “Cake”]
Input:
Foods[0]
Output:
‘Salad’