码迷,mamicode.com
首页 > 编程语言 > 详细

python打印空格

时间:2020-11-08 17:02:21      阅读:26      评论:0      收藏:0      [点我收藏+]

标签:python   简单方法   多个   lan   pre   world   and   ref   ace   

例1:打印空间的简单方法

print(‘ ‘)
print(" ")
print("Hello world!")
print("Hello world")

输出量

Hello world!
Hello world

例2:在单个打印语句中打印时在两个值之间打印空格

x = 10
y = 20

print("x:",x)
print("y:",y)

输出量

x: 10
y: 20

例3:在两个值之间给多个空格

x = 10
y = 20

space = ‘ ‘

‘‘‘
  2 spaces would be here
  1 space after first parameter,
  1 space by using space variable
  1 space after second parameter
‘‘‘
print("Hello",space,"world")

‘‘‘
  7 spaces would be here
  1 space after first parameter,
  5 space by using space*5
  1 space after second parameter
‘‘‘
print("Hello",space*5,"world")

‘‘‘
  12 spaces would be here
  1 space after first parameter,
  10 space by using space*10
  1 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

 以为上几个python打印空格的小例子,以供大家参考

 

python打印空格

标签:python   简单方法   多个   lan   pre   world   and   ref   ace   

原文地址:https://www.cnblogs.com/summerxbc/p/13941083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!