Download our e-book of Introduction To Python
Shekhar Ravat
3 years ago
list_1 = [96, 97.5, 'Physics','Chemistry']
list_2 = [1, 2, 3, 4, 5 ]
list_3 = ["a", "b", "c", "d"]
#!/usr/bin/python
list_1 = [96, 97.5, 'Physics','Chemistry']
list_2 = [1, 2, 3, 4, 5 ]
print("list_1[2]: ", list_1[2])
print("list_2[2:]: ", list_2[2:])
list_1[2]: Physics
list_2[2:]: [3, 4, 5]
#!/usr/bin/python
list = ['physics', 'chemistry', 1997, 2000]
print("Value available at index 2 : ")
print(list[2])
list[2] = 2001
print("New value available at index 2 : ")
print(list[2])
Value available at index 2 :
1997
New value available at index 2 :
2001
#!/usr/bin/python
list_1 = ['physics', 'chemistry', 1997, 2000]
print(list_1)
del list_1[2]
print("After deleting value at index position 2 : ")
print(list_1)
print("=============")
list_1.remove('physics)
print(list_1)
['physics', 'chemistry', 1997, 2000]
After deleting value at index position 2 :
['physics', 'chemistry', 2000]
=============
['chemistry, 2000]
list_1 = ['Physics', 'Chemistry']
list_2 = ['Math', 'Science', 'Social']
list_1.append(list_2)
print(list_1)
print("===========================")
# again execute same set of code by using extend attribute
list_1 = ['Physics', 'Chemistry']
list_2 = ['Math', 'Science', 'Social']
list_1.extend(list_2)
print(list_1)
['Physics', 'Chemistry', ['Math', 'Science', 'Social']]
===========================
['Physics', 'Chemistry','Math', 'Science', 'Social']