%s格式话字符串。%d,%f
name = 'tom'
age = 15
weight = 72.3
stu_id = 1
print('我是%s,我今年%d岁了,我的体重是%.2f公斤,我的学号是%06d' % (name, age, weight,stu_id))
#我是tom,我今年15岁了,我的体重是72.30公斤,我的学号是000001
- %06d,表示输出的整数显示位数,不足以0不全,超出当前位数则原样输出
- %.2f,表示小数点后显示的小数位数。
f格式化字符串 f’{表达式}’
#python3.6版本以上能用
name = 'tom'
age = 15
weight = 72.3
stu_id = 1
print(f'我的名字是{name},年龄是{age},体重是{weight},学号是{stu_id}')
#我的名字是tom,年龄是15,体重是72.3,学号是1
转义字符
\n
:换行 (反斜杠n)\t
:制表符:一个tab键的距离
print('hello\nworld')
###
hello
world
###
print('hello\tworld')
###
hello world
###
结束符 end='\n或者\t'
#print默认是换行显示的,如果第一个加了end='\t',就变成制表形式了
print('hello,world',end='\t')
print('hello,world' ,end='\n')
# hello,world hello,world