You are on page 1of 4

Practical No.

GUIDELINES FOR WRITING THE PRACTICAL WRITEUP

1. Use ruled file pages for write-up of practical contents.


2. You can use both side ruled pages for the same.
3. Start each practical (experiment) write-up on new page.
4. Maintain all these practical work in a file as it will be considered for
TW (continuous assessment) of the course PWP.
5. Take print out of programs or can write it on assignment pages.
6. Complete the practical write-up in time. Don’t keep it pending.

Practical No. 6: Write python program to perform following operations on Lists:


Create list, Access list, Update list, Delete list

1. When to use Lists in Python?

Ans:
Lists are one of the four built-in data structures in Python, together with tuples, dictionaries,
and sets. They are used to store an ordered collection of items, which might be of different
types. Commas separate the elements that are contained within a list and enclosed in square
brackets.

2. Justify the statement “List are mutable”.

Ans:

Unlike strings, lists are mutable. This means we can change an item in a list by accessing it
directly as part of the assignment statement. Using the indexing operator (square brackets) on
the left side of an assignment, we can update one of the list items. ... Item assignment does not
work for strings.
Practical No. 6

1. Write a program to sum all items in a list


list=[10,20,30,40,50]
sum=0
for i in list:
sum=sum+i
print("sum= ",sum)

Output:
>>> %Run exp6_1.py
sum= 150

2. Write a python to multiply all items in a list


list=[1,2,3,4,5]
var=1
for i in list:
var=var*i
print("Multiple product of all list items= ",var)

Output:
>>> %Run exp6_2.py
Multiple product of all list items= 120

3. Write a python program to get the largest number from a


list
list=[10,20,30,40,50]
print("Largest Number is: ",max(list))

Output:
>>> %Run exp6_3.py
Largest Number is: 50
Practical No. 6

4. Write a python program tp get the smallest number from


a list
list=[10,20,30,40,50]
print("Smallest Number is: ",min(list))

Output:
>>> %Run exp6_4.py
Smallest Number is: 10

5. Write a python program to reverse a list


list=[10,20,30,40,50]
print("Original list is: ",list)
list.reverse()
print("Reverse of list is: ",list)

Output:
>>> %Run exp6_5.py
Original list is: [10, 20, 30, 40, 50]
Reverse of list is: [50, 40, 30, 20, 10]

6. Write a python program to find common items from a list


list1=[33,44,77,22,66]
list2=[28,33,35,22,88]
for i in list1:
for j in list2:
if i==j:
print(i," is common")

Output:
>>> %Run exp6_6.py
33 is common
22 is common
Practical No. 6

7. Write a python program to select even items of a list


list=[22,35,45,46,77,88,90,100]
print("Even Items are: ")
for i in list:
if i%2==0:
print(i)

Output:
>>> %Run exp6_7.py
Even Items are:
22
46
88
90
100

You might also like