pycharm输入返回一个int而不是字符串?

时间:2018-09-23 00:09:11

标签: python pycharm python-2.x

我是python编程的新手。我正在使用最新版本的pyCharm并对raspberrypi上的某些代码进行远程调试。有此代码。

# Get the verifier code from the user. Do this however you
# want, as long as the user gives the application the code.
verifier = input('Verifier code: ')

在控制台窗口中输入117-820-181之类的字符串的地方,在veriifer变量中它显示为整数。在下一行,代码中断,因为它期望验证程序是字符串而不是int。 有什么想法为什么要返回int而不是string?

2 个答案:

答案 0 :(得分:1)

在输入中将其设为字符串

    verifier = str(input('Verifier code: '))

答案 1 :(得分:1)

我相信您正在使用Python 2.x(input,该版本将给定的输入作为代码进行评估,这似乎正在发生。此外,我认为PyCharm喜欢使用Python2.x。而不是3.x。

如果是这样,请使用raw_input()(它以str的形式返回所有内容,就像Python 3.x的input()函数一样):

verifier = raw_input('Verifier code: ')

这将停止将验证码转换为int eger的问题。

相关问题