Informatics Practices
Select the output of the following expression:
str1 = "pen"
print(list(str1))
- ['p', 'e', 'n' ]
- [pen]
- [p/e/n]
- { "pen" }
Python List Manipulation
1 Like
Answer
['p', 'e', 'n']
Reason — The list() function in Python can be used to convert a string into a list of its individual characters. Therefore, when we execute list(str1) where str1 = "pen", it will convert the string "pen" into a list containing its characters: ['p', 'e', 'n'].
Answered By
1 Like
Related Questions
Which of the following commands will create a list?
- List1=list ()
- List1= []
- List1=[1,2,3,"a"]
- All of these
What is the use of append() function in list?
- It adds an item to the end of the list.
- It adds an item at the beginning of the list.
- It adds an item anywhere in the list.
- All of these
The sequential accessing of each of the elements in a list is called:
- List Indexing
- List Traversal
- List Slicing
- List Accessing
Consider the following lists:
L1 = ["this", "is", "a", "list"] L2 = ["this", "is", "another list"]Which of the following statements will result in an error?
- L1 = L2
- L1.copy()
- L2.append(1, 2, 3)
- L2.pop()