Jan-12-2018, 12:33 PM
(Jan-12-2018, 10:29 AM)Sandesh Wrote: dict = {'Name': 'Zara', 'Age': 7}
print ("Value :" , dict.items())
if i run the above code i supposed to get= Value :([('Name', 'Zara'), ('Age', 7)]).
But i am getting it as=Value : dict_items([('Name', 'Zara'), ('Age', 7)])..
Help me out...
Firstly please use bbcode to wrap you code around. You have better chances of getting help, than one without it.
Quote:dict = {'Name': 'Zara', 'Age': 7} print ("Value :" , dict.items())if i run the above code i supposed to get=Value :([('Name', 'Zara'), ('Age', 7)])
.
But i am getting it as=Value : dict_items([('Name', 'Zara'), ('Age', 7)])
..
Help me out...
And I suspect that your getting this output
Value : dict_items([('Name', 'Zara'), ('Age', 7)])
. Is because how the __repr__ magic method had been implemented for dict class in python3. In Python2 the output is what you expect. However this has changed in python>>> dict = {'Name': 'Zara', 'Age': 7} >>> dict {'Age': 7, 'Name': 'Zara'} >>> dict.items() [('Age', 7), ('Name', 'Zara')]