Python list
list, dictionary, tuple
list and dictionary are other programming language has. It’s simple.
list is array data structure, and dictionary key-value store.
tuple is a kind of list, and difference is immutable.
Those data structure is useful for programming.
※ This will work in Python3
list
Sample
list = [] list2 = ['A', 'B', 'C'] nicorinpana = ['Nico', 'Hanayo', 'Rin'] print(list2[1]) # Add item list.append('ABC') print(list) # Delete item del list2[1] # Length print(list2.__len__()) print(len(list2)) print(len(list)) # Enumeration for i,j in enumerate(nicorinpana): print(j)
dictionary
dic = {} dic2 = {"honoka" : "kousaka", "kotori" : "minami"} print(dic2["honoka"]) dic2['hanayo'] = 'koizumi' print(dic2) print(dic2.keys()) print(dic2.values()) print('umi' in dic2) for key, value in dic2.items(): print(key + ":" + value)
tuple
jojo3 = ('Jotaro', 'Jostar', 'Kakyoin', 'Pornalef') # cannot change value print(jojo3[2]) print(len(jojo3)) for i,j in enumerate(jojo3): print(j)