python3的输入函数input

那么这个函数在python2升级到python3后做了哪些改变?

首先在python2中有input和raw_input两个函数,其中raw_input将所有输入作为字符串看待,返回字符串类型。

input函数支持表达式、数字类型、字符串类型,接受为表达式时,只返回其执行结果。

在python3中对input和raw_input函数进行了整合,仅保留了input函数(认为raw_input函数是冗余的)。

同时改变了input的用法——将所有的输入按照字符串进行处理,并返回一个字符串。
 

a=input("please input a number:")
b=list(map(int,a.split(",")))
c=sorted(b)
d="".join(a.split(','))
e=map(str,a.split(","))
print (a,b,c,d,e)

运行结果:

please input a number:2,1,5,9,3
2,1,5,9,3

[2, 1, 5, 9, 3]

[1, 2, 3, 5, 9]

21593

<map object at 0x00000146C03B7F08>

猜你喜欢

转载自blog.csdn.net/qq_35924690/article/details/119987527
今日推荐