+ 2

Use of items() and dictionares in python

I'm learning how to use dictionaries and the method items() when I have this code: dic = {"1": 100, "2": 200}; for x in dic.items(): print(x); The ouput will be ('1', 100) ('2', 200) but if I use: for x, y in dic.items(): print(x, y); The ouput will be: 1 100 2 200 why in the first code, the output is with the quotation mark, and the second code, there is no quotation mark? What is the difference? and which one is better to use?

6th May 2018, 9:25 PM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
1 Answer
10th May 2018, 4:57 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar