How do I insert multiple variables with string formatting?

Something to notice about the str.format() method …

def spam():
    print('Sam-I-am')
    return 'am'

print('S{0}-{1}-{0}'.format(spam(), 'I'))

What will the output be? Execute the code to find out.

How may times did the spam() function get called?

4 Likes