- 1

output of following code??explain briefly please

d = {'foo': 1, 'bar': 2, 'baz': 3} while d: print(d.popitem()) print('Done.')

17th Apr 2020, 2:26 PM
Radhey
Radhey - avatar
1 Antwort
+ 3
While d: it denotes the values in the d. Which means until d becomes false perform following.. d.popitem() It is a function that performs pop operation. Pop operation is removing the last item.(for more info learn abt stack). as it is in while loop it removes the items in the d continuously until it becomes null. Aftering removing all items in d , it exits from while loop and then follows the print statement (done..) Hope u understood..
17th Apr 2020, 2:41 PM
Sujithra