1. 程式人生 > >python3.0 怎麼輸出到一行上

python3.0 怎麼輸出到一行上

在print()括號內要輸出的引數後面加上end,只後加上你要的間隔符,如:

phrase = "A bird in the hand..."
for char in phrase:
    if(char == "A" or char == 'a'):
        print ('X')
    else:
        print (char')

在這裡插入圖片描述

phrase = "A bird in the hand..."
for char in phrase:
    if(char == "A" or char == 'a'):
        print ('X',end='')
    else:
        print (char,end='')

在這裡插入圖片描述