Creating Lists Using the List Function in Python
You can also make a list using the list function. In this case, the entry has a slightly longer form than when using square brackets:
lst = list()
Next, we pass the element we want to add to the list to the list function parameter. However, there is an important nuance here. In essence, the list function converts the element specified in its parameter to a list. Let's make a list consisting of one line:
lst = list('1')
print(lst) # ['1']
If we want to add several elements to the list, we can pass them as one long string:
lst = list('1234')
print(lst) # ['1', '2', '3', '4']
When trying to pass a number to the function, we get an error:
lst = list(1234)
print(lst) # will display an error
The following code is given:
tst = list('abcde')
print(tst)
Tell me what will be output to the console.
The following code is given:
tst = list('a12b')
print(tst)
Tell me what will be output to the console.
The following code is given:
tst = list(5678)
print(tst)
Tell me what will be output to the console.
The following code is given:
tst = list('4321')
print(tst)
Tell me what will be output to the console.