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)]
πŸ’¬ Discuss
βœ… Correct Answer: (A) [(1,0),(2,0),(2,1)]
Explanation: It’s a nested loop. The output of the first “for” loop will be the value of the next loop.
Explanation by: Rajeev Malhotra
It’s a nested loop. The output of the first “for” loop will be the value of the next loop.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
243
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Rajeev Malhotra
Publisher
πŸ“ˆ
87%
Success Rate