📜  如何在 Python3 中打印空格?

📅  最后修改于: 2022-05-13 01:55:36.572000             🧑  作者: Mango

如何在 Python3 中打印空格?

在本文中,我们将学习如何在Python编程语言中打印空格或多个空格。 Python语言中的间距比其他编程语言非常简单。在 C 语言中,要打印 10 个空格,使用循环,而在Python中,不使用循环来打印空格数。

以下是打印空间的示例:

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

Python3
# Python program to print spaces
  
# No spaces
print("GeeksForGeeks")
  
# To print the blank lines
print(' ')
  
# Also print the blanks
print(" ")
  
# To print the spaces in sentence
print("Geeks  For    Geeks")


Python3
# Python program to print spaces
x = 1
y = 2
  
# use of "," symbol
print("x:",x)
print("y:",y)
print(x,"+",y,"=",x+y)


Python3
# Python program to print spaces
  
# To print the single spaces in sentence
print("Geeks"+" "+"For"+" "+"Geeks")
print("Geeks","For","Geeks")
  
# to print spaces by given times
print("Geeks"+" "*3+"For"+" "*3+"Geeks")
print("Geeks"+" "*5+"For"+" "*10+"Geeks")


输出:

GeeksForGeeks
 
 
Geeks  For    Geeks


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

Python3

# Python program to print spaces
x = 1
y = 2
  
# use of "," symbol
print("x:",x)
print("y:",y)
print(x,"+",y,"=",x+y)

输出:

x: 1
y: 2
1 + 2 = 3


示例 3:在两个值之间打印多个空格。

Python3

# Python program to print spaces
  
# To print the single spaces in sentence
print("Geeks"+" "+"For"+" "+"Geeks")
print("Geeks","For","Geeks")
  
# to print spaces by given times
print("Geeks"+" "*3+"For"+" "*3+"Geeks")
print("Geeks"+" "*5+"For"+" "*10+"Geeks")

输出:

Geeks For Geeks
Geeks For Geeks
Geeks   For   Geeks
Geeks     For          Geeks