Python2与python3区别(二)

来源:互联网 发布:淘宝售后时间是多久 编辑:程序博客网 时间:2024/06/06 08:59

from pip._vendor.distlib.compat import raw_inputnum = 50guess = raw_input("please input :")if guess == num: print('equal')elif guess < num : print('lower')else: print('>')print ("Done!")
运行结果如下:Traceback (most recent call last):  File "F:\JA\TestPython\guess.py", line 7, in <module>    elif guess < num :TypeError: '<' not supported between instances of 'str' and 'int'原因:input()返回的数据类型是str,不能直接和整数进行比较,所以要用int()将str换成整数即可
第三行应该这样写:
guess = int(raw_input("please input :"))