** How to make a list ** [Element 1, Element 2, Element 3] Separated by ,.
List example List of strings ["sushi" , "ramen"]
List of numbers [100 , 200]
** Assign a list to a variable **
fruits = ["apple" , "banana" , "strawberry"]
** Output list, get element ** List output
fruits = ["apple" , "banana" , "strawberry"]
print(fruits)
Output result ["apple" , "banana" , "strawberry"]
Get list elements Variable [index number] Variable is a list assigned
fruits = ["apple" , "banana" , "strawberry"]
print("My favorite fruit is" + fruits[1] + "is")
Output result My favorite food is banana
** Overwriting elements ** List [index number] = value
fruits = ["apple" , "banana" , "strawberry"]
fruits[1] = "kiwi"
** Add element ** List .append (value)
fruits = ["apple" , "banana" , "strawberry"]
fruits.append("kiwi")
Recommended Posts