# Creating an empty list called "num" num = [ ] # Adding the values inside the list num = [ 1, 2, 3, 4, 5] # Printing the list num # Adding the values irrespective of their data type: Integer, String, float. num = [1, 2, 3, "Tanu", 4.0, 4/2] num # Create a list as num num = [1, 2, 3, 4, 5] # Use type method by passing the name of the list as an arguement type(num) # Creating a list called name name = ["Tanu", "Nanda", "Prabhu"] name # Accessing the elements in the list name[0] # Tanu # Calculating the length of the list. len(name) # Calculating the length of individual elements in a list len(name[0]) # length of "Tanu" is 4 # Creating a list called name name = ["Tanu", "Nanda", "Prabhu"] name # Creating an empty list names names = [] names # Using assignment operator on Lists doesn't create a copy. names = name # Assigning the old list name to the new list names. names # Creating a new list called Cars cars = ["Mercedes", "BMW", "Audi"] cars # Creating a new list called bikes bikes = ["Honda", "Yamaha", "Aprilla"] bikes # Appending both the lists cars_bikes = cars + bikes cars_bikes # Creating a list num = [1, 2, 3, 4, 5] # Assigning sum to 0 sum = 0 # Using a for loop to iterate over the list for i in num: sum = sum + i print(sum) # 15 # Creating a list num = [1, 2, 3, 4, 5] if 1 in num: print("True") else: print("False") # Range starts 0 to n-1 for i in range(5): print(i) # Initialisin i to 0 i = 0 while i < 10: print(i) # 0–9 i = i+ 1 # Creating a new list called name name = ['Tanu', 'Nanda'] # Before appending name # Using the append operation on the current ("Prabhu") is the value to be appended. name.append("Prabhu") # After appending name # Creating a new list called list name = ['Tanu', 'Nanda'] # Before inserting name # Insert Operation on the existing list, here the index position is 2. name.insert(2, "Prabhu") # After Inserting name # Creating a new list called name name = ['Tanu', 'Nanda'] # Before extending name # Using extend but make sure that you put the elements in a [] # Without [] name.extend("Prabhu") # After extending name # After [] name.extend(["Prabhu"]) name # Creating a new list called name name = ['Tanu', 'Nanda'] # Before indexing name # After indexing, type the element that you want to index. name.index("Nanda") # If the element is not present then you get an error name.index("Mercedes") # Creating a new list called name name = ['Tanu', 'Nanda'] # Before removing name # After removing name.remove("Nanda") name name.remove('Prabhu') # Creating a list called num num = [1, 4, 5, 2, 3] # Before sorting num # After sorting num.sort() num # Creating a list called num num = [1, 2, 3, 4, 5] # Before Reversing num num.reverse() # After the reverse num # Creating a list called num num = [1, 2, 3, 4, 5] # Before popping num # After popping num.pop(1) num char = ['a', 'b', 'c', 'd'] char ['a', 'b', 'c', 'd'] char[1:-1] ## ['b', 'c'] char char[0:2] = 'z' ## replace ['a', 'b'] with ['z'] char ## ['z', 'c', 'd'] # Creating a String String = "Tanu" String # Checking for the type type(String) # Using the split method to split the string into a list. name = list(String.split(" ")) name type(name)