What will be the output of the following Python code? [code]s=["pune", "mumbai", "delhi"] [(w.upper(), len(w)) for w in s][/code]

What will be the output of the following Python code?
Code:
s=["pune", "mumbai", "delhi"]
[(w.upper(), len(w)) for w in s]
A. Error
B. [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]
C. [PUNE, 4, MUMBAI, 6, DELHI, 5]
D. [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]
 
Answer: d
Explanation: If we need to generate two results, we need to put it in the form of a tuple. The code shown above returns each word of list in uppercase, along with the length of the word. Hence the output of the code is: [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)].
 

Tìm kiếm

Back
Top