What is the expected output of the following code?

What is the expected output of the following code?

print(list(‘hello’))
A . None of the above.
B. hello
C. [h, e, l, l, o]
D. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
E. [‘h’ ‘e’ ‘l’ ‘l’ ‘o’]

Answer: D

Explanation:

Topic: list()

Try it yourself:

print(list(‘hello’)) # [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

A string is a sequence of characters

and works very fine with the list() function.

The result is a list of strings, in which every character is a string of its own.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments