List Data Type in Python
Concept List is a collection which is mutable, ordered and changeable. Allows duplicate members. List are just like the arrays, declared in other languages. List can contain int, float, str, list, dict, set any data type. Code Example Example 1: # empty list >>> l = [] [] Example 2: >>> l = [10, 20.35, 'Hello'] [10, 20.35, 'Hello'] Example 3: >>> l = [10, 20.35, 'Hello'] >>> len(l) 3 >>> l [1] 20.35 # append >>> l.append("New") [10, 20.35, 'Hello', 'New'] >> l [1: 3] [20.35, 'Hello'] >>> l [-3, -1] 20.35, 'Hello'] >>> l [0] = 40 >>> l [40, 20.35, 'Hello', 'New'] # reverse >>> l.reverse() >>> l ['New', 'Hello', 20.35, 40] # extend >>> l = ['New', 'Hello', 20.35, 10] >>> l1 = ['a', 'b'] >>> l.extend(l1) >>> l ['N