Python lists are container that is used to store a list of values of any data type. In simple words we can say that list is a collection of any data type items or elements.
E.g. list1 [‘harry’, ‘ram’, ‘Aakash’, ‘shyam’, 5, 4.85]
The above list contains strings, integer and even float type data. It means above list contains any kind of data means it’s not mandatory to form list of only one data type. List can contain any kind of data in it.
List elements are also accessed by using Indexes i.e. first element of list possess 0 index then second as 1 and so on.
Note : if you put any index which isn’t in the list i.e. that index is not there in list then you will get an error.
List Methods :
Here is the list of list methods of Python.
List Slicing :
List slices, like string slices are the sub part of a list extracted out. You can use indexes of list elements to create list slices as per following format :
Here also slicing will go from start index to stop index-1. It means from specified start index to specified stop index – 1.
List Methods :
Types of Data Types :
Tuple is an immutable data type in Python. Tuple is a collection of elements enclosed in () (parentheses). Tuple once defined can’t be changed i.e. its elements or values can’t be altered or manipulated.
Note: To create tuple of one element it is necessary to put ‘,’ after that one element i.e. like this tup=(1,) because if we write only 1 then interpreter will understand it as a simple number or integer that’s why it’s important to use ‘,’ after single element.
Swapping of two numbers :
grocery = ["Harpic", "vim bar", "deodrant", "Bhindi", "Lollypop", 56] # print(grocery) numbers = [2, 7, 9, 11, 3] # numbers.remove(9) # numbers.pop() # numbers.sort() # numbers =  # numbers.reverse() # numbers.append(1) # numbers.append(72) # numbers.append(5) # numbers.insert(2, 67) # print(numbers) # 3, 11, 9, 7, 2 # print(numbers) # numbers = 98 # print(numbers) # Mutable - can change # Immutable - cannot change # tp = (1,) # print(tp) a= 1 b = 8 a, b = b,a # temp = a # a = b # b = temp print(a, b)
Any Course related announcements will be posted here