python列印空格
阿新 • • 發佈:2020-11-07
例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列印空格的小例子,以供大家參考