🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

निम्नलिखित कोड का परिणाम क्या है ?

What is the output of the following code ?

WM=[‘b’ * x for x in range(4)]
print(WM)
A)
B)
C)
D)

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 from 0 to 3.

  • In each iteration, it multiplies the string 'b' by the current value of x.

  • For x = 0: 'b' * 0 results in an empty string ''.

  • For x = 1: 'b' * 1 results in 'b'.

  • For x = 2: 'b' * 2 results in 'bb'.

  • For x = 3: 'b' * 3 results in 'bbb'.

So, the list WM will be: ['', 'b', 'bb', 'bbb'].

Answer: (A) ['', 'b', 'bb', 'bbb'].

Latest Updates