list 1 - list 2 python code example

Example 1: python list

# example of list in python

myList = [9, 'hello', 2, 'python']

print(myList[0]) # output --> 9
print(myList[-3]) # output --> hello
print(myList[:3]) # output --> [9, 'hello', 2]
print(myList) # output --> [9, 'hello', 2, 'python']

Example 2: get an item out of a list python

#to get the LAST item out of a list:
things = ["apple", "book", 3, ["another list", 85], "orange"]
last = things.pop()
print(last)
#it should output "orange"

Example 3: how to make a list in python

list = [1, 2, 3, 4, 5, 6, 7]

Example 4: making lists in python

# list with numbers
list = [10, 20, 30]
# list with strings
list = ["john", "kai", "albert"]
# mixed data
list = ["john",1 ,True ]

Example 5: python lists

games = ['Fortnite', 'CS:GO', 'Temple Run']
print(games)

Tags:

Cpp Example