How to create list in Python
#create list
a=["priya", 5,9.8,'vish']
print(a)
print(type(a))
#list with indexing
b=["vish",'priya',5,9.8]
print(b[1])
print(b[-1])
print(b[0:3])
#update
b[2]="priyavish"
print(b)
print(len(b))
#adding at the last of list
b.append("uma")
print(b)
#to insert value at specific position
b.insert(4,"python")
print(b)
b.remove("priya")
print(b)
#del(b)
b.clear()
print(b)
list1=["a","b","c"]
list2=[1,2,3]
list1.extend(list2)
print(list1)
nickname=['vish','priya','war']
nickname.insert(1,"machinelearning")
print(nickname)
nickname=['vish','priya','war','war','vish','war']
x=nickname.count("war")
print("the war is:",x)
nickname=['vish','priya','war']
nickname.reverse()
print("reserve is:",nickname)
list1=["a","b","c"]
list2=[1,2,3]
list3=list1+list2
print("total list:",list3)
if "priya" in a:
print("yes,'priya' is in the nickname")
for x in a:
print(x)
for x in list2:
list1.append(x)
print(x)
list1 = (input("Enter: ")).split()
print(list1)
Comments
Post a Comment