0% found this document useful (0 votes)
20 views5 pages

Python EXP1

worksheet for begginer list in python

Uploaded by

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

Python EXP1

worksheet for begginer list in python

Uploaded by

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

Experiment-2

Student Name: Ritik Chauhan UID: 24MCA20311


Branch: MCA Section/Group: 24MCA-5B
Semester: 1st Date of Performance: 12/08/2024
Subject Name: Python Programming Subject Code: 24CAH-606

Aim:Write a program to perform list operations, creating, assecing, slicing,


modifing, adding, removing, sorting, finding length & looping through the list.

:Overview of the practical:

• Creating a List: Initialize a list using square brackets, e.g., my_list =


[1, 2, 3]
• Accessing Elements: Retrieve elements by index, e.g., my_list[0]
for the first element
• Updating Elements: Modify elements by assigning a new value to a
specific index, e.g., my_list[1] = 20.
• Adding Elements: Use methods like append(), extend(), or
insert() to add elements to the list, e.g., my_list.append(4).
• Removing Elements: Remove elements with methods like remove(),
pop(), or del, e.g., my_list.remove(2) or del my_list[1].

Code:

#creating a list
list=[5,10,15,20,25,30]
print("Original List:",list)

#access the list item

print("accessing element index =3 in the list:",list[3])

#slicing the list

print("Slicing the list, Start index = 2, till index = 4(element at index 4 not
included):",list[2:4])

#modifying a list

list[2]=22

print("modifing the element at index = 1 with '2':",list)

# append add the item end of the list

list.append(265)

print("Append add the new element end of the list:",list)

#add the new element in the list using index

list.insert(0,111)

print("Insert adds an element index of the list:",list)

#removing the element

list.remove(20)

print("remove the element mention from the list:",list)

#using pop opration

list.pop(5)

print("pop remove the element to the index num given:",list)

#sort the list accending order

list.sort()

print("e list in accending order:",list)


# reverse the list decending order

list.reverse()

print("e list in decending order:",list)

#find the lenght of the list

a=len(list)

print("Lenght of list:",a)

# using loop

print("All the element present in the list using for loop")

for a in list:

print

Output:
Learning outcomes:

1 Efficiently Manage Data: Lists allow you to store and manipulate collections of items,
enabling you to handle various types of data in a structured way.
2 Access and Modify Elements: You can access, update, and modify individual elements
using indexing, making lists flexible for dynamic data manipulation.
3 Add and Remove Items: Lists provide methods to add new items (append(), extend(),
insert()) and remove items (remove(), pop(), del), allowing for versatile data handling
4 Utilize List Methods: Python lists come with built-in methods that simplify common
tasks, such as sorting, counting occurrences, and finding elements, streamlining data
operations and enhancing productivity.
5 Add and Remove Items: Lists provide methods to add new items (append(), extend(),
insert()) and remove items (remove(), pop(), del), allowing for versatile data handling

You might also like