我是一个需要几个值的字符串替代品,我想知道是否可以跳过一个键并将其留在那里,而不是用空格填充它?
s='%(name)s has a %(animal)s that is %(animal_age)s years old'
#skip the animal value
s = s % {'name': 'Dolly', 'animal': 'bird'}#, 'animal_age': 10}
print s
预期输出:
Dolly has a bird that is %(animal_age)s years old