list
'''
1.add a element at last position:
append
syntax:
list_var.append(value)
data=["sam",23,10000,"delhi",110034]
print(data)
data.append(89)
print(data)
2.pop
i.delete a element from a list of
last element
data=["sam",23,10000,"delhi",110034]
print(data)
data.pop()
print(data)
ii.delete an element from
specific position
data=["sam",23,10000,"delhi",110034]
print(data)
data.pop(0)
print(data)
3.count
=====
count is used to count s specific
element from a list
data=["sam","sam","Sam",23,10000,"delhi",110034]
print(data)
print(data.count("sam"))
4.len:count the number of elements
===
data=["sam","sam","Sam",23,10000,"delhi",110034]
print(data)
print(len(data))
5.insert:used to insert an element from
===== a list to the specific
position.
num=[3,4,3,5]
num.insert(1,56)
print(num)
6.copy
====
num=[3,4,3,5,4,7,3]
copied_list=num.copy()
print(copied_list)
7.clear:used to delete all the elements
=====
data=["max",1000,110023,384773893,"delhi"]
print(data)
data.clear()
print(data)
8.reverse:used to create a reverse of the
====== list
data=["max",1000,110023,384773893,"delhi"]
data.reverse()
print(data)
9.extend:add elements of one list
====== to another list
data=["sam",28]
print(data)
data.extend([3,4,6,3,6])
print(data)
10.insert: add elements in a list
====== to specific position
data=["sam",28]
print(data)
data.insert(1,"sam")
print(data)
11.remove: remove the specified element
======
data=["sam",28]
print(data)
data.remove(28)
print(data)
12.sort
====
id=[4,6,4,6,84,2,5]
names=["h","w","a","u","o","d"]
id.sort()
print("ASCENDING:",id)
id.sort(reverse=True)
print("DESCENDING:",id)
names.sort()
print("ASCENDING",names)
names.sort(reverse=True)
print("DESCENDING:",names)
'''
id=[4,6,4,6,84,2,5]
names=["h","w","a","u","o","d"]
id.sort()
print("ASCENDING:",id)
id.sort(reverse=True)
print("DESCENDING:",id)
names.sort()
print("ASCENDING",names)
names.sort(reverse=True)
print("DESCENDING:",names)
clear:delete all elements of a list
id=[4,6,4,6,84,2,5]
print(id)
id.clear()
print(id)
0 Comments