a=["way of kings","words or radiant","Oathbringer","Rhythm of War"]# print all itemsprint(a)# print first itemprint(a[0])# change first itema[0]="Vivek"# print first itemprint(a[0])
list to store unlimited inputs from user
names=[]whileTrue:print("Enter New Name")name=input()ifname=="":breaknames=names+[name]print("Names Are:")fornameinnames:print(name)
Using List of multiple types
a=["way of kings",1,bool]print(a)
List with multiple Index
#multy Index Listnames=[["Kaledin","Dalenar"],["Navani","Yashnah"]]print(names[0])print(names[0][1])
a=["way of kings","words or radiant","Oathbringer","Rhythm of War"]# Print First two itemsprint(a[0:2])# Print Last two itemsprint(a[-2:])
List Functions
a=[5,2,6,3,7]# print numbers in ascending ordera.sort()print(a)# print numbers in descending ordera.reverse()print(a)# Add new number at enda.append(8)print(a)# Add number at 3rd positiona.insert(2,4)print(a)# remove element from 3rd positiona.pop(2)print(a)# remove specific element from lista.remove(2)print(a)