You're not looking at dictionary formatting, you're looking at tuples.
In Python, multiple-element tuples look like:
1,2,3
The essential elements are the commas between each element of the tuple. Multiple-element tuples may be written with a trailing comma, e.g.
1,2,3,
but the trailing comma is completely optional. Just like all other expressions in Python, multiple-element tuples may be enclosed in parentheses, e.g.
(1,2,3)
or
(1,2,3,)
Use string formatting instead:
ex_dict={1:"how",3:"do you",7:"dotoday"}
for key in ex_dict:
print("{} and this is {}".format(key,ex_dict[key]))
Additionally: You can simplify your code with
ex_dict={1:"how",3:"do you",7:"dotoday"}
for key, val in ex_dict.iteritems(): #ex_dict.items() in python3
print("{} and this is {}".format(key,val))
Finally: be forewarned that dictionaries in python have arbitrary order. If you want your ordering to be always the same, it's safer to use collections.OrderedDict. Because otherwise, you're depending on implementation detail. Want to see it for yourself? Make ex_dict = {1:"how",3:"do you",7:"dotoday", 9:"hi"}
.
import collections
ex_dict= collections.OrderedDict([(1,"how"),(3,"do you"),(7,"dotoday")])
for key, val in ex_dict.iteritems(): #ex_dict.items() in python3
print("{} and this is {}".format(key,val))