Q:

Manipulating and printing items in a python dictionary

I have the following code:
ex_dict={1:"how",3:"do you",7:"dotoday"}
for key in ex_dict:
    string= key," and this is ", ex_dict[key]
    print (string)

The output is: 
(1, ' and this is ', 'how')
(3, ' and this is ', 'do you')
(7, ' and this is ', 'dotoday')

My intended output:
1 and this is how
3 and this is do you
7 and this is dotoday

I can't seem to figure out how to get rid of the dictionary formatting in my output.

A:

Just use + to combine strings:
string = str(key) + " and this is " + ex_dict[key]

Since key is an integer, and you can only concatenate strings using the + operator, you should convert key to string as well.

A:

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))

