python打印空格_如何在 Python 中打印空格?

python打印空格

Example 1: A simple way to print spaces

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

print(' ')
print(" ")
print("Hello world!")
print("Hello         world")

Output

输出量

 
 
Hello world!
Hello         world

Example 2: Printing spaces between two values while printing in a single print statement

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

x = 10
y = 20

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

Output

输出量

x: 10
y: 20

Example 3: Give multiple spaces between two values

示例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)

Output

输出量

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 中打印空格?)