Report Bug
Qus :

what is the output of the following code?

M=['b' *x for x in range(4)]
print(M)

Qus

निम्नलिखित कोड का आउटपुट क्या है?

M=['b' *x for x in range(4)]
print(M)


A. ['', 'b', 'bb', 'bbb']
B. ['b,'bb', "bbb', "bbbb']
C. ['b','bb', bbb']
D. none of these


Solution
A. ['', 'b', 'bb', 'bbb']



Explanation
<p>range(4) gives: [0, 1, 2, 3]</p><p><span style="font-size: 1rem; letter-spacing: 0.01rem;">'b' * x repeats the character 'b' x times</span></p><p><b>So:</b></p><p>'b' * 0 → ''</p><p>'b' * 1 → 'b'</p><p>'b' * 2 → 'bb'</p><p>'b' * 3 → 'bbb'</p>



Report Bug