第一種輸出方式:print輸出
>>>print('Hello world!')
Hello world!#通過轉(zhuǎn)義字符\n進(jìn)行換行輸出
>>>print('Hello\nworld!')
Hello
world!
print 在輸出后默認(rèn)是換行的友题,如果要實(shí)現(xiàn)不換行輸出瞧省,只需要在變量末尾加上 end="":
# 不換行輸出
print(" 輸出結(jié)果:", end=" " )
print( a, end=" " )
print(b, end=" " )
輸出結(jié)果:a b
第二種輸出方式:格式化輸出
>>>enscore = 100
>>>chscore = 99
>>>print("My English score is %d"%enscore)
My English score is 100
>>>print("My English score is %d....My Chinese score is %d"%(enscore,chscore))
My English score is 100....My Chinese score is 99
補(bǔ)充:
要有輸出,就需要先要有輸入,上面的兩種輸入都是我們預(yù)先既定好的,但是如果想要程序獲取我們?nèi)藶檩斎氲模蔷托枰玫降却斎搿?/p>
python3的用法:
>>>input("請(qǐng)輸入密碼:")
請(qǐng)輸入密碼:▎
python2的用法:
>>>raw_input("請(qǐng)輸入密碼:")
請(qǐng)輸入密碼:▎
>>>input("請(qǐng)輸入密碼:")
請(qǐng)輸入密碼:▎
說明:
- 在Python3中,只能用input(),不能用raw_input()嫂用。
- 在Python2中,input()和raw_input()都可以用丈冬,但兩者區(qū)別在于嘱函,input()會(huì)把你輸入的當(dāng)作是表達(dá)式來看待,而raw_input()會(huì)把你輸入的原封不動(dòng)地保存下來埂蕊。