新聞中心
計(jì)算機(jī)編程中,會(huì)經(jīng)常涉及輸入輸出。任何程序都需通過輸入輸出功能與用戶進(jìn)行交互和溝通。所謂輸入就是指程序捕獲用戶通過鍵盤輸入的信息或數(shù)據(jù),而輸出則是指程序向用戶顯示內(nèi)容或打印數(shù)據(jù)。在Python語(yǔ)言中,用input()函數(shù)獲取用戶輸入,用print() 函數(shù)表示輸出。

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供靈山網(wǎng)站建設(shè)、靈山做網(wǎng)站、靈山網(wǎng)站設(shè)計(jì)、靈山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、靈山企業(yè)網(wǎng)站模板建站服務(wù),十余年靈山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
1、input()函數(shù) (輸入函數(shù))
Python提供了一個(gè)input()函數(shù),可以讓用戶輸入字符串,并且存放在變量中,比如輸入用戶名
>>> name = input() jean
輸入的內(nèi)容:
>>> name 'jean'
或者使用:
>>> print(name) jean
有時(shí)候需要友好的提示一下,我們也可以這樣做:
>>> name = input("place enter your name")
place input your name jean
>>> print("hello,", name)
hello, jean2、print()函數(shù)(輸出函數(shù))
輸出指定的內(nèi)容
print("hello world")print()函數(shù)可以同時(shí)輸出多個(gè)字符串,用逗號(hào)“,”隔開
print("hello","how","are","you")print()會(huì)依次打印每個(gè)字符串,遇到逗號(hào)“,”會(huì)輸出空格,輸出的內(nèi)容是這樣的:
hello how are you
print()可以打印整數(shù),或者計(jì)算結(jié)果
>>>print(300) 300 >>>print(100 + 200) 300
我們也可以把打印的結(jié)果顯示的再漂亮一些
>>>print("100 + 200 =", 100 + 200)
100 + 200 = 300注意:對(duì)于字符串"100 + 200 ="它會(huì)原樣輸出,但是對(duì)于100+200,python解釋器自動(dòng)計(jì)算出結(jié)果為300,因此會(huì)打印出上述的結(jié)果。
字符串相加,進(jìn)行字符串的連接,且不產(chǎn)生空格
print("hello","你好")
# 使用”,“進(jìn)行連接
print("he" + "llo")
# 字符串相加,進(jìn)行字符串的連接,且不產(chǎn)生空格
print(10+30)
# 沒有使用引號(hào)括起來,默認(rèn)為數(shù)值,若是使用引號(hào)括起來,就是字符串
# 若是數(shù)值使用加號(hào)連接,默認(rèn)是表達(dá)式進(jìn)行計(jì)算,返回計(jì)算的結(jié)果
print("hello"+1) #會(huì)報(bào)錯(cuò)
# 不同類型的數(shù)據(jù)不能使用加號(hào)連接
# 不同類型的數(shù)據(jù)能夠使用”,“進(jìn)行連接
print("1 2 3",2+3)
# 輸入
# input()
# 帶有提示信息的輸入
# name = input("請(qǐng)輸入您的姓名:")
# print(name)python中print之后是默認(rèn)換行的,要實(shí)現(xiàn)不換行要加end參數(shù)表明
n = 0
while n <= 100:
print("n =",n,end=' ')
if n == 20:
break
n += 1
輸出:
n = 0 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 n = 10 n = 11 n = 12 n = 13 n = 14 n = 15 n = 16 n = 17 n = 18 n = 19 n = 20多個(gè)數(shù)值進(jìn)行比較
print('c'>'b'>'a')
print(5>1>2)
輸出:
True
False補(bǔ)充:
1、input()函數(shù):無論用戶輸入什么內(nèi)容,該函數(shù)都將返回字符串類型;
2、print()函數(shù):將內(nèi)容按照一定的格式輸出到控制臺(tái)。
做什么事情都需要不斷地堅(jiān)持下去,編程也一樣?,F(xiàn)在python語(yǔ)言十分火熱,職場(chǎng)對(duì)python的需求也很高,薪資待遇都很棒,所以希望新手小白們能堅(jiān)持學(xué)習(xí)哦~
當(dāng)前名稱:創(chuàng)新互聯(lián)Python教程:新手學(xué)python之Python的輸入輸出函數(shù)
分享網(wǎng)址:http://fisionsoft.com.cn/article/cooseec.html


咨詢
建站咨詢
