Python中字符串格式化的方法有两种:
name = 'Alice' age = 25 print('My name is %s and I am %d years old' % (name, age))
format()
name = 'Bob' age = 30 print('My name is {} and I am {} years old'.format(name, age))
推荐使用第二种方法,因为它更为灵活,支持更多的格式化选项。