print(f'my name is {name.capitalize()}.') # my name is Jack.
print(f'I am {age:*^10} years old.') # I am ****18**** years old.
print(f'I am a {sex}') # I am a man
print(f'My salary is {salary:10.3f}') # My salary is 9999.990
# 不带参数
print('{} {}'.format('hello','world')) # 结果:hello world
# 带数字参数
print('{0} {1}'.format('hello','world')) # 结果:hello world
# 参数顺序倒乱
print('{0} {1} {0}'.format('hello','world')) # 结果:hello world hello
# 带关键字参数
print('{a} {tom} {a}'.format(tom='hello',a='world')) # 结果:world hello world
Python programming, data formatted output (character splicing)
Guess you like
Origin blog.csdn.net/qq_43307934/article/details/112056197
Ranking