xxxxxxxxxx
#creating a list
create_list = ["apple", "banana", "cherry"]
print(create_list)
xxxxxxxxxx
# Create a list
new_list = []
# Add items to the list
item1 = "string1"
item2 = "string2"
new_list.append(item1)
new_list.append(item2)
# Access list items
print(new_list[0])
print(new_list[1])
xxxxxxxxxx
myList = [value,value,value] #note that you can use any amount of value
#you don not have to use value
make list python
xxxxxxxxxx
list_variable = ["element 1", 2, 3.0] # list with a string, integer, and float
list_variable2 = [
["a", "f", "g"],
["b", "e", "h"],
["c", "d", "i"] ] # 2D list
xxxxxxxxxx
pythonCopyl = [] # empty list
l = [2, 4, 6, 8] # elements of same data type
l = [2, 'Python', 1+2j] # elements of different data type
xxxxxxxxxx
my_list = ['p', 'r', 'o', 'b', 'e']
# first item
print(my_list[0]) # p
# third item
print(my_list[2]) # o
# fifth item
print(my_list[4]) # e
# Nested List
n_list = ["Happy", [2, 0, 1, 5]]
# Nested indexing
print(n_list[0][1])
print(n_list[1][3])
# Error! Only integer can be used for indexing
print(my_list[4.0])
xxxxxxxxxx
# list with numbers
list = [10, 20, 30]
# list with strings
list = ["john", "kai", "albert"]
# mixed data
list = ["john",1 ,True ]