list in pyhton code example

Example 1: how to use a list in python

# empty list
my_list = []

# list of integers
my_list = [1, 2, 3]

# list with mixed data types
my_list = [1, "Hello", 3.4]

Example 2: 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 3: how to make lists in python

blah = [uchoose,etc.]

Example 4: list in python

thislist = ["apple", "banana", "cherry"]
print(thislist[1])

Example 5: list in python

myfavouritefoods = ["Pizza", "burgers" , "chocolate"]
print(myfavouritefoods[1])
#or
print(myfavouritefoods)

Example 6: lists in python

lst = ["abc", 34, True, 40, "male"]
for i in lst:
	print(i)

Tags:

Cpp Example