Study Notes (04): 100 Python Interview Lectures (Based on Python3.x) - Please describe the usage of the print function in detail

Study now:https://edu.csdn.net/course/play/26755/340118?utm_source=blogtoedu

Usage of print function:

1. Use the separator between sep parameter strings, the default is space;

2. Use the end parameter to set the ending symbol. The default is a newline character;

3. You can use % to format strings;

# print函数的用法:
# 1,使用sep参数字符串之间的分隔符,默认是空格;
print('太阳有','大行星',sep='八')
# 2,使用end参数设置结尾符号,默认是换行符;
print('水星',end=' ')
print('金星',end=' ')
print('地球',end=' ')
print('火星',end=' ')
print('木星',end=' ')
print('土星',end=' ')
print('天王星',end=' ')
print('海王星')
# 3,可以使用%格式化字符串;
s='地球到月球的距离'
x=38
print('%s是%d万公里'%(s,x))

The result is as follows:

太阳有八大行星
水星 金星 地球 火星 木星 土星 天王星 海王星
地球到月球的距离是38万公里

 

Guess you like

Origin blog.csdn.net/Smile_Lai/article/details/104544516