List

List of Data Structures in Python

List Definition One of the data structure in python. Almost same as array in other languages. Object. Data Structures in Python List Tuple Dictionary set declaration temp=[] temp=list() temp=[5,9,44] index structure characteristic List in List is possible. This is same as 2D array in other languages String in python is same as List slicing [starting index : ending index-1 : condition index] [0:8:3] = select index 0 to 7 by adding 3 [:8:] = select index 0 to 7 by adding 1 [7::] = select index 7 to -1 by adding 1 [::-1] = select index 0 to -1 by adding -1 a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print(a[0:8:3]) # [0, 3, 6] print(a[:8:]) # [0, 1, 2, 3, 4, 5, 6, 7] print(a[7::]) # [7, 8, 9] print(a[::-1]) # [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Arithmetic Operation a=[1,2,3] b=["apple","house","computer"] print(a+b) # [1, 2, 3, 'apple', 'house', 'computer'] # print(a+3) # error # print(a-b) # error # print(a-3) # error # print(a*b) # error print(b*3) # ['apple', 'house', 'computer', 'apple', 'house', 'computer', 'apple', 'house', 'computer'] print(b*0) # [] # print(a/b) # error # print(a/3) # error add element append() = add a new element behind extend() = add new elements behind insert() = add new elements by index [] = add new elements by index condition a=[1,2,3,4,5,6,7,8,9] b=["apple","house","computer"] a.