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

Apurv Py 2.1.

Uploaded by

lsomesh448
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)
12 views5 pages

Apurv Py 2.1.

Uploaded by

lsomesh448
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/ 5

Name: Ankush bhakare

Roll No.: 14
Assignment No.: 02(2.1)
Assignment Title: Develop programs to learn different types of structures (list, dictionary,
tuples) in python

Code:

2.1 List:
2.1.1 Create and display list in python
Student_Name = ["Apurv", "Bhavesh", "Ankush", "Mohan", "Krushna", "Tushar"]

print(Student_Name)

for i in range(len(Student_Name)):
print(Student_Name[i])

Output:
['Apurv', 'Bhavesh', 'Ankush', 'Mohan', 'Krushna', 'Tushar']
Apurv
Bhavesh
Ankush
Mohan
Krushna
Tushar

2.1.2List Slicing in python


# Print all items
print(Student_Name[:])
Output:
['Apurv', 'Bhavesh', 'Ankush', 'Mohan', 'Krushna', 'Tushar']

# Print certain range


print(Student_Name[3:5])

Output:
['Mohan', 'Krushna']
# print from starting range
print(Student_Name[3:])

Output:
['Mohan', 'Krushna', 'Tushar']

# print upto given range


print(Student_Name[:6])

Output:
['Apurv', 'Bhavesh', 'Ankush', 'Mohan', 'Krushna', 'Tushar']

2.1.3Copy List in python


1. copy:

import copy

copy_Student_Name = copy.copy(Student_Name)

for i in range(len(copy_Student_Name)):

print(copy_Student_Name[i])

Output:
Apurv
Bhavesh
Ankush
Mohan
Krushna
Tushar

2. deepcopy:

import copy

Deep_Copy_Student_Name = copy.deepcopy(Student_Name)

for i in range(len(Deep_Copy_Student_Name)):

print(Deep_Copy_Student_Name[i])

Output:
Apurv
Bhavesh
Ankush
Mohan
Krushna
Tushar

2.1.4.clear:
Student_Name.clear()
print(Student_Name)

Output:.

[]

2.1.5.extend:
Student_Name = ["Sandip", "Mohu", "Vishnavi", "Bindiya", "Anjali", "Lina", "Shahid"]
Student_Name.extend(["Tanuja","Ketan", "Sejal"])

for i in range(len(Student_Name)):
print(Student_Name[i])

Output:
Apurv
Bhavesh
Ankush
Mohan
Krushna
Tushar
Rishi
Ketan
Pawan

2.1.6.index:
print(Student_Name.index("Ketan"))

Output:

2.1.7List Membership in python


list1 = [1, 2, 3, 6, 5]
list2 = [6, 7, 10, 9]
for item in list1:
if item in list2:
print("overlapping")
else:
print("not overlapping")

Output:
not overlapping
not overlapping
not overlapping
overlapping
not overlapping

OR

x = int(input("Enter a number: "))


list = [10, 20, 30, 40, 50]

if (x not in list):
print(x, " is NOT present in given list")
else:
print(x, " is present in given list")

Output:
Enter a number: 30
30 is present in given list

2.1.8List Deletion in python

Student_Name = ["Sandip", "Mohu", "Vishnavi", "Bindiya", "Anjali", "Lina", "Shahid"]

del Student_Name
print(Student_Name)

Output:
NameError Traceback (most recent
call last)
Cell In[1], line 4
1 Student_Name = ["Sandip", "Mohu", "Vishnavi", "Bindiya",
"Anjali", "Lina", "Shahid"]
3 del Student_Name
----> 4 print(Student_Name)
NameError: name 'Student_Name' is not defined

OR

Student_Name = ["Sandip", "Mohu", "Vishnavi", "Bindiya", "Anjali", "Lina", "Shahid"]

Student_Name.remove("Mohu")
for i in range(len(Student_Name)):
print(Student_Name[i])

Output:
Sandip
Vishnavi
Bindiya
Anjali
Lina
Shahid

You might also like