例1:列印空間的簡單方法
print(' ')print(" ")
print("hello world!")
print("hello world")
輸出量
hello world!hello world
例2:在單個列印語句中列印時在兩個值之間列印空格
x = 10y = 20
print("x:",x)
print("y:",y)
輸出量
x: 10y: 20
例3:在兩個值之間給多個空格
x = 10y = 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 worldhello world
hello world
hello # world
hello ##### world
hello ########## world
x: 10
y: 20
python語言列印菱形 Python列印菱形
示例1 usr bin python coding utf 8 根據輸入列印 rows int raw input please input number 列印菱形上半部分 for i in range rows for j in range rows i print j 1 for k in ra...
python語言列印菱形 Python列印菱形
示例1 usr bin python coding utf 8 根據輸入列印 rows int raw input please input number 列印菱形上半部分 for i in range rows for j in range rows i print j 1 for k in ra...
python 列印對齊 python 列印對齊
一 數值型別 int float d f是佔位符 a 3.1415926 print d a d只能輸出整數,int類 print f a f輸出浮點數 3.141593 print 2f a 按照要求輸出小數字數 3.14 print 9f a 如果要求的小數字數過多,後面就用0補全 3.1415...