1 format函数
print("我最爱的水果是{},我最爱的学科是{}".format("苹果","数学"))结果:我最爱的水果是苹果,我最爱的学科是数学-----------------------------------print("姓名:{name},年龄:{age}".format(name="math and code",age=1))结果:姓名:math and code,年龄:1
2 f-strings
name="math and code"print(f"我的名字是{name}")结果:我的名字是math and code
3 %方式
name="math and code"print("我的名字是%s"%name)结果:我的名字是math and code
注:
%s 字符串%c 单个字符%e 指数 (基底写为e)%E 指数 (基底写为E)%f 浮点数%F 浮点数,与上相同%g 指数(e)或浮点数 (根据显示长度)%G 指数(E)或浮点数 (根据显示长度)%% 字符"%"
输入数据格式要与输出格式保持一致!



