how to use list() in python 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: list in python

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

Example 3: list in python

#list is data structure 
#used to store different types of data at same place
list = ['this is str', 12, 12.2, True]

Example 4: python list function

# empty list
print(list())

# vowel string
vowel_string = 'aeiou'
print(list(vowel_string))

# vowel tuple
vowel_tuple = ('a', 'e', 'i', 'o', 'u')
print(list(vowel_tuple))

# vowel list
vowel_list = ['a', 'e', 'i', 'o', 'u']
print(list(vowel_list))

Example 5: python list constructor

nuts = list("pecan nut", "walnut", "cashew nut", "macadamia nut")

forrests_favorites = list(nuts) # makes a new list with the same content