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))
推荐使用第二种方法,因为它更为灵活,支持更多的格式化选项。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Python中字符串格式化的操作是什么