CBSE Class 11 Informatics Practices Question 29 of 80

Lists in Python — Question 7

Back to all questions
7
Question

Question 7

Select the output of the following expression:

str1 = "pen"
print(list(str1))
  1. ['p', 'e', 'n' ]
  2. [pen]
  3. [p/e/n]
  4. { "pen" }
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'].