निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
WM=[‘b’ * x for x in range(4)]
print(WM) A
[‘’, ‘b’, ‘bb’, ‘bbb’]
B
[‘b’, ‘bb’, ‘bbb’, ‘bbbb’]
C
[ ‘b’, ‘bb’, ‘bbb’]
D
None of these
Explanation
Let's break down the code:
WM = ['b' * x for x in range(4)]
print(WM)
-
The list comprehension
['b' * x for x in range(4)]iterates over the range of numbers from0to3. -
In each iteration, it multiplies the string
'b'by the current value ofx. -
For
x = 0:'b' * 0results in an empty string''. -
For
x = 1:'b' * 1results in'b'. -
For
x = 2:'b' * 2results in'bb'. -
For
x = 3:'b' * 3results in'bbb'.
So, the list WM will be: ['', 'b', 'bb', 'bbb'].
Answer: (A) ['', 'b', 'bb', 'bbb'].
Correct Answer: A) [‘’, ‘b’, ‘bb’, ‘bbb’]