学习笔记(04):Python 面试100讲(基于Python3.x)-请详细描述print函数的用法

立即学习:https://edu.csdn.net/course/play/26755/340118?utm_source=blogtoedu

print函数的用法:

1,使用sep参数字符串之间的分隔符,默认是空格;

2,使用end参数设置结尾符号,默认是换行符;

3,可以使用%格式化字符串;

# 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))

结果如下:

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

猜你喜欢

转载自blog.csdn.net/Smile_Lai/article/details/104544516