python打印空格


例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打印空格的小例子,以供大家參考

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM