python 1.0+ (printf-style-string-formatting)
name = 'world'
print('hello %s' % name)
# 'hello world'
python 2.6+ (PEP 3101 -- Advanced String Formatting)
action = 'hello'
name = 'guest'
language = 'python'
print('{0} {name}, welcome to {language} world'.format(
action, name=name, language=language))
# hello guest, welcome to python world
python 3.6+ (PEP 498 -- Literal String Interpolation)
action = 'hello'
name = 'guest'
language = 'python'
print(f'{action} {name}, welcome to {language} world')
# hello guest, welcome to python world
网友评论