pycharm 输入 returns 一个整数而不是字符串?
pycharm input returns an int instead of string?
我是 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: ')
我在控制台 window 中输入了一些字符串,例如 117-820-181,并且在 veriifer 变量中它显示为一个 int。在下一行代码中断,因为它期望验证器是字符串而不是 int。
知道为什么这会返回 int 而不是 string 吗?
在输入时将其设为字符串
verifier = str(input('Verifier code: '))
我相信您正在使用 Python 2.x(input
在该版本中将给定的输入作为代码进行评估,这似乎正在发生。此外,我认为PyCharm 喜欢使用 Python 2.x 而不是 3.x).
如果是这样,则使用 raw_input()
(其中 returns 一切都作为 str
ing,很像 Python 3.x 的 input()
函数执行):
verifier = raw_input('Verifier code: ')
这将解决验证码变成int
eger 的问题。
我是 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: ')
我在控制台 window 中输入了一些字符串,例如 117-820-181,并且在 veriifer 变量中它显示为一个 int。在下一行代码中断,因为它期望验证器是字符串而不是 int。 知道为什么这会返回 int 而不是 string 吗?
在输入时将其设为字符串
verifier = str(input('Verifier code: '))
我相信您正在使用 Python 2.x(input
在该版本中将给定的输入作为代码进行评估,这似乎正在发生。此外,我认为PyCharm 喜欢使用 Python 2.x 而不是 3.x).
如果是这样,则使用 raw_input()
(其中 returns 一切都作为 str
ing,很像 Python 3.x 的 input()
函数执行):
verifier = raw_input('Verifier code: ')
这将解决验证码变成int
eger 的问题。