0% found this document useful (0 votes)
6 views2 pages

Expt8.ipynb - Colaboratory

The document outlines various Python functions, including defining functions, calling functions, using arguments and parameters, and returning values. It provides examples of functions with default parameters, arbitrary arguments, and passing lists as arguments. Additionally, it includes examples of functions for mathematical operations and conditional statements.

Uploaded by

AN Mn OL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Expt8.ipynb - Colaboratory

The document outlines various Python functions, including defining functions, calling functions, using arguments and parameters, and returning values. It provides examples of functions with default parameters, arbitrary arguments, and passing lists as arguments. Additionally, it includes examples of functions for mathematical operations and conditional statements.

Uploaded by

AN Mn OL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

12/12/23, 8:43 PM expt8.

ipynb - Colaboratory

 EXPERIMENT 8

NAME: ANUDEEP KALE

ROLL NO.: 36

SECTION: A(A2)

FUNCTIONS

DEFINING A FUNCTION

def my_functin():

print("Hello from my

function") CALLING A

FUNCTION

def my_function():
print("Hello from my
function") my_function()

Hello from my function

ARGUMENTS AND PARAMETERS

def my_function(fname):
print(fname + " Khan")
my_function("Salman")
my_function("Aamir")
my_function("Shahrukh")

Salman Khan
Aamir Khan
Shahrukh Khan

def my_function(fname, lname):


print(fname + " " + lname)
my_function("Salman", "Khan")

Salman Khan

ARBITRARY ARGUMENTS, *args

def my_function(*fruits):
print("The sweetest fruit is " +
fruits[2]) my_function("Banana","Apple",
"Papaya")

The sweetest fruit is

Papaya DEFAULT PARAMETER

VALUES

def my_function(country =
"Norway"): print("I am from "
+ country) my_function("Sweden")
my_function()
my_function("India")

I am from Sweden
I am from Norway
I am from India

PASSING A LIST AS AN ARGUMENT

def my_function(food): for x in


food: print(x) fruits =

https://colab.research.google.com/drive/1esD-vl1U7t6SghZJhZ_XZyCTp29ZnCkk#scrollTo=bIV8OmkHlZ-H&printMode=true
12/12/23, 8:43 PM expt8.ipynb - Colaboratory
["apple", "banana", "mango"]
my_function(fruits)
apple
banana mango

RETURN
VALUES

def my_function(x):
return 5*x
print(my_function(1))
print(my_function(2))
print(my_function(3))

5
10
15

def sum(numbers):
total = 0 for x in
numbers: total += x
return total
print(sum((8, 2, 5, 6,
5)))

26

def add_numbers(x,
y): sum = x + y
return sum

num1 = 5
num2 = 6
print("The sum is ", add_numbers(num1,
num2))

The sum is 11

def even_odd(x):
if x % 2 == 0:
print("even")
else:
print("odd")

even_odd(2)
even_odd(3)

even
odd

def swap(x,
y): temp =
x x = y y
= temp

x = 2 y =
3

swap(x,
y)
print(x)
print(y)

2
3

https://colab.research.google.com/drive/1esD-vl1U7t6SghZJhZ_XZyCTp29ZnCkk#scrollTo=bIV8OmkHlZ-H&printMode=true

You might also like