A

Admin • 833K Points
Coach

Q. What is the output of the following code?

Code:
[ (a,b) for a in range(3) for b in range(a) ]
  • (A) [(1,0),(2,0),(2,1)]
  • (B) [(1,0),(2,1),(2,1)]
  • (C) [(0,0),(1,1),(2,2)]
  • (D) [(1,0),(2,1),(3,2)]
  • Correct Answer - Option(A)
  • Views: 27
  • Filed under category Python
  • Hashtags:

Explanation by: Admin

It’s a nested loop. The output of the first “for” loop will be the value of the next loop.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.