What's the difference between the three output style?


my_dict = {"apple": 3, "peach": 15, "banana": 10}
for key in my_dict:
    print key, str(my_dict[key])
    print key, (my_dict[key])
    print key + " " + str(my_dict[key])

Thanks in advance!


The output is exactly the same


There is no difference in the result.

Please note that using str function here -> str(my_dict[key]) is completely redundant. Print calls str, there is no need to call it explicitly.


Oh, that is unknown to me before. And your answer helps clear my confusion, thank you :slight_smile:


You're very welcome :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.