adplus-dvertising
frame-decoration

Question

What is the output of the following?
my_string = "hello world"
k = [(i.upper(), len(i)) for i in my_string]
print(k)

a.

[(‘HELLO’, 5), (‘WORLD’, 5)].

b.

[(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)].

c.

[(‘HELLO WORLD’, 11)].

d.

none of the mentioned

Posted under Python

Answer: (b).[(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)].

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the following?