d = {'first': 'Robert', 'last': 'Paulson'}
print("His name was {first} {last}!".format(**d))
>> His name was Robert Paulson!
class Person:
def __init__(self, first, last):
self.first, self.last = first, last
p = Person('Robert', 'Paulson')
print("His name is {0.first} {0.last}!".format(p))
>> His name was Robert Paulson!
You also do not need to know what type is being passed in as the __str__ method is used for .format().
macbony|12 years ago
rsfinn|12 years ago
pekk|12 years ago