Python List

Run Settings
LanguagePython
Language Version
Run Command
# thislist = ['one', 'two', 'three'] # print(thislist[-1]) # thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] # print(thislist[2:5]) # thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] # print(thislist[:4]) # thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] # print(thislist[2:]) cars = ['volvo', 'toyota', 'bmw', 'nissan', 'ford', 'honda'] print(cars) if 'toyota' in cars: print("Yes, there is a Japanase car on the list") # cars[1] = 'Lexus' # print(cars) fruits = ['apple', 'banana', 'cherry', 'orange', 'kiwi', 'mango'] print(fruits) fruits[1:3]=['blackcurrant', 'watermelon'] # this will replace banana and cherry print(fruits) fruits = ['apple', 'banana', 'cherry', 'orange', 'kiwi', 'mango'] print(fruits) fruits[1:2]=['blackcurrant', 'watermelon'] # This will replace banana with two values print(fruits) fruits = ['apple', 'banana', 'cherry', 'orange', 'kiwi', 'mango'] print(fruits) fruits[1:3]=['blackcurrant'] # This will replace the banana with blackcurrant and cherry with will be moved print(fruits) fruits = ['apple', 'banana', 'cherry', 'orange', 'kiwi', 'mango'] print(fruits) fruits.insert(2,'blackcurrant') # to add and item at index(position) 2 print(fruits) fruits = ['apple', 'banana', 'cherry', 'orange', 'kiwi', 'mango'] print(fruits) fruits.append('Orange') # to add an item at the end print(fruits) fruits = ['apple', 'banana', 'cherry'] print(fruits) tropicalfruits = ['mango', 'pineapple', 'papaya'] print(tropicalfruits) fruits.extend(tropicalfruits) print(fruits) thislist = ["apple", "banana", "cherry"] thistuple = ("kiwi", "orange") thislist.extend(thistuple) print(thislist) print(type(thislist)) thislist = ["apple", "banana", "cherry"] thislist.remove('banana') # This will remove online the first occurance print(thislist) thislist = ["apple", "banana", "cherry"] thislist.pop(1) # This will remove the item with the index number specified, else the last item will be romeve print(thislist) thislist = ["apple", "banana", "cherry"] del thislist[0] # this will delete the content of the index item print(thislist) thislist = ["apple", "banana", "cherry"] del thislist # this will delete the whole list # print(thislist) thislist = ["apple", "banana", "cherry"] thislist.clear() # this will clear the content of the list, but not delete the list print(thislist) thislist = ["apple", "banana", "cherry"] for x in thislist: # this will print out all the items in the list line by line print(x)
Editor Settings
Theme
Key bindings
Full width
Lines