--- output control character used Python

%s     字符串
%d     有符号十进制整数
%f     浮点数
%c     字符
%x     十六进制

Simple usage

dog_color = 'yellow'
dog_height = 50

print('有一只狗,它有%dcm高,它的颜色是%s' % (dog_height, dog_color))

Output

Here Insert Picture Description
or

dog_color = 'yellow'
dog_height = 50

print(f'有一只狗,它有{dog_height}cm高,它的颜色是{dog_color}')

Get the same result

Change the terminator Print

print('窗前明月光')
print('疑是地上霜')
print('举头望明月')
print('低头思故乡')

The output
Here Insert Picture Description
print default newline terminator is
changed to their needs terminator is used as follows:

print('窗前明月光', end=",")
print('疑是地上霜', end=",")
print('举头望明月', end=",")
print('低头思故乡', end="。")

The results are as follows
Here Insert Picture Description
such as tabs

print('窗前明月光', end="\t")
print('疑是地上霜', end="\t")
print('举头望明月', end="\t")
print('低头思故乡', end="\t")

Output

Here Insert Picture Description

Published 14 original articles · won praise 30 · views 8734

Guess you like

Origin blog.csdn.net/weixin_43086497/article/details/104866321