新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python里input怎么解釋
python中input函數(shù)有類似c中的scanf函數(shù)的功能。

Python2中input使用如下:
>>>x = input("x:")
x: 3
>>>y = input("y:" )
y: 4
>>> print x*y
12但是Python3中input使用會有如下的提示:
>>> x = input("x:")
x:3
>>> y = input("y:")
y:4
>>> print (x*y)
Traceback (most recent call last):
File "", line 1, in
TypeError: can't multiply sequence by non-int of type 'str'
>>> 原因:
Python3以后的版本中,raw_input和input合體了,取消了raw_input,并用input代替,所以說現(xiàn)在版本的input接受的是字符串,可以如下處理:
>>> x = int(input("x:"))
x:3
>>> y = int(input("y:"))
y:4
>>> print (x*y)
12更多學(xué)習(xí)內(nèi)容,請點(diǎn)擊Python學(xué)習(xí)網(wǎng)。
當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:python里input怎么解釋
標(biāo)題路徑:http://www.dlmjj.cn/article/djchpps.html


咨詢
建站咨詢
