Report Bug

Qus

What will be the output of the following Python code snippet?

  my_string = "hello world"  k = [(i.upper(), len(i)) for i in my_string]  print(k)
Qusनिम्नलिखित Python कोड स्निपेट का आउटपुट क्या होगा?


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


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



Explanation
We are iterating over each letter in the string.
CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad