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

निम्नलिखित पायथन प्रोग्रामों का आउटपुट पता करें:

Find out the output of the following Python programs:

def gfg(x,l=[]):
    for i in range(x):
        l.append(i*i)
    print(l)
gfg(2)
A)
B)
C)
D)

Explanation:

Let's analyze the given Python code step by step:

def gfg(x, l=[]):
    for i in range(x):
        l.append(i * i)
    print(l)

gfg(2)
  1. Function gfg:

    • It takes two parameters: x and l. l has a default value of an empty list [].
    • Inside the function, a loop runs from 0 to x-1 (inclusive). In each iteration, it appends i*i (the square of i) to the list l.
  2. Calling gfg(2):

    • x = 2 and l uses the default value [] (an empty list).
    • The loop will run for i = 0 and i = 1:
      • When i = 0: 0*0 = 0, so 0 is appended to the list.
      • When i = 1: 1*1 = 1, so 1 is appended to the list.
  3. Final result: After the loop, the list l will contain [0, 1] and that will be printed.

Output:

(B) [0, 1]

Explanation:

  • Since the list l starts empty and the loop runs twice (for i = 0 and i = 1), the final list becomes [0, 1].
Latest Updates