What's the difference between the three output style?


#1

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!


#2

The output is exactly the same


#3

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.


#4

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


#5

You're very welcome :slight_smile:


#6

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