格式化输入方式一
%:占位符
s:string,字符串
d:digit,数字
%%:显示单纯的%
1 print("我叫%s,今年%岁,身高%s。"%(name,age,height))
msg = "我叫%s,今年%岁,身高%s。"%(name,age,height) print(msg)
注意:如果print的内容中包含%号:
msg = "我叫%s,今年%岁,身高%s,学习进度为3%%。"%(name,age,height) #前一个%表示转义字符 print(msg)
格式化输入方式二
name ='A' sex='man' age=18 msg = F'姓名:{nanme},性别:{sex},年龄:{age}' #小写f也可以 print(msg)
print(f'{4-3'} name='A' print(f'{name.lower()}') ar={'name':'A','age':11} msg = f'name is {ar['name']},age is {ar['age']}' print(msg) #多行f speaker = f'Hi {name}.'\ f'You are {age} years old.'\ f'You are a {ajd} guy!' print(spearker) #使用lambda表达式 x=5 print(f'{(lambda x: x*2) (x)}')
参考来源博客:
https://www.cnblogs.com/jin-xin/articles/10478209.html