新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python的鍵盤輸入是什么
Python中獲取鍵盤輸入的函數(shù)是input(),在Python2和Python3中,input函數(shù)有所不同。

raw_input函數(shù)
raw_input() 函數(shù)從標(biāo)準(zhǔn)輸入讀取一個行,并返回一個字符串(去掉結(jié)尾的換行符):
str = raw_input("Enter your input: ");
print "Received input is : ", str這將提示你輸入任意字符串,然后在屏幕上顯示相同的字符串。當(dāng)我輸入"Hello Python!",它的輸出如下:
Enter your input: Hello Python Received input is : Hello Python
input函數(shù)
input() 函數(shù)和raw_input() 函數(shù)基本可以互換,但是input會假設(shè)你的輸入是一個有效的Python表達(dá)式,并返回運算結(jié)果。這應(yīng)該是兩者的區(qū)別。
str = input("Enter your input: ");
print "Received input is : ", str這會產(chǎn)生如下的對應(yīng)著輸入的結(jié)果:
Enter your input: [x*5 for x in range(2,10,2)] Recieved input is : [10, 20, 30, 40]
python學(xué)習(xí)網(wǎng),免費的python學(xué)習(xí)網(wǎng)站,歡迎在線學(xué)習(xí)!
網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:python的鍵盤輸入是什么
新聞來源:http://www.dlmjj.cn/article/dhdgscs.html


咨詢
建站咨詢
