Why does the order of the arguments matter?

They are flipped around because of the order in which they are interpolated in the string. TITLE, first, then, POET. It doesn’t matter what order they are given in the parameter so long as the arguments in the call expression match the correct variable.

If the parameters are written,

(title, poet)

then arguments must be,

("I Hear America Singing", "Walt Whitman")

else if written as such,

(poet, title)

then the arguments must be,

("Walt Whitman", "I Hear America Singing")

Either way won’t matter to the output string. The format arguments are ordered according to how they present.

Now in a case where we wish to have both lists the same, say,

(poet, title)

in the parameters, and,

(poet, title)

in the format arguments, we can use numbers in the placeholder to identify which argument goes where…

'The poem "{2}" is written by {1}.'.format(poet, title)
3 Likes