每日一课 | python打印空格
示例1:打印空间的简单方法
print(' ')
print(" ")
print("Hello world!")
print("Hello world")
输出量
Hello world!
Hello world
示例2:在单个打印语句中打印时在两个值之间打印空格
x = 10
y = 20print("x:",x)
print("y:",y)
输出量
x: 10
y: 20
示例3:在两个值之间给多个空格
x = 10
y = 20space = ' ''''2 spaces would be here1 space after first parameter,1 space by using space variable1 space after second parameter
'''
print("Hello",space,"world")'''7 spaces would be here1 space after first parameter,5 space by using space*51 space after second parameter
'''
print("Hello",space*5,"world")'''12 spaces would be here1 space after first parameter,10 space by using space*101 space after second parameter
'''
print("Hello",space*10,"world")# for better better understanding
# assign space by any other character
# Here, I am assigning '#'
space = '#'
print("Hello",space,"world")
print("Hello",space*5,"world")
print("Hello",space*10,"world")# printing values of x and y with spaces
space = ' '
print("x:",space*10,x)
print("y:",space*10,y)
输出量
Hello world
Hello world
Hello world
Hello # world
Hello ##### world
Hello ########## world
x: 10
y: 20
翻译自: https://www.includehelp.com/python/how-to-print-spaces-in-python.aspx
推荐阅读--
每日一课 | python烤地瓜案例
每日一课 | python逐行处理文件
每日一课 | python条件语句多条件
每日一课 | Python保存程序
每日一课 | python 元组解构赋值
今日福利
扫码免费领取课程
????????
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
