arrow
arrow
arrow
For the following Python statement Txt = list('PEACE') What shall be the output of print(Txt)?
Question

For the following Python statement
Txt = list('PEACE')
What shall be the output of print(Txt)?

A.

['P', 'E', 'A', 'C', 'E']

B.

[P, E, A, C, E]

C.

Error in statement

D.

['PEACE']

Correct option is A


The given Python statement:
Txt = list('PEACE')
converts the string 'PEACE' into a list of individual characters. The list() function takes an iterable (like a string) and converts it into a list where each character becomes a separate element.
Thus, the output of print(Txt) will be:
['P', 'E', 'A', 'C', 'E']
Important Key Points:
1. list() Function: The list() function takes an iterable (such as a string) and converts it into a list, where each element of the iterable becomes a separate item in the list.
2. String to List Conversion: In this case, the string 'PEACE' is converted into a list where each character of the string becomes an individual element of the list.
3. List Representation: Lists are represented by square brackets [], with each element separated by a comma.
Knowledge Booster:
· Option (b): [P, E, A, C, E] is incorrect because it is missing quotes around the characters. In Python, the list elements need to be enclosed in quotes if they are strings.
· Option (c): There is no error in the statement. The list() function is used correctly.
· Option (d): ['PEACE'] is incorrect because it would be the result of creating a list with the string 'PEACE' as a single element. However, list('PEACE') converts the string into separate characters, not a single string element.

Free Tests

Free
Must Attempt

CDP Subject Test 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon20 Mins
languageIcon English
Free
Must Attempt

EVS Subject Test 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon20 Mins
languageIcon English
Free
Must Attempt

CTET Paper-I PYP (07 July 2024)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
test-prime-package

Access ‘EMRS PGT’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
289k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow