Discuss / Python / input 和 raw_input 的区别

input 和 raw_input 的区别

Topic source

代码如下: name=input('please enter your name\n') print('hello',name)

直接在命令行运行时 ,输入字符串后点击回车 提示字符串未定义

反复查资料以后 解决方案如下: 1、用input函数,手动输入字符串时 用‘’或“”括起来 需要是正规py表达式 2、将input替换为raw_input

因为 raw_input可以接受控制台输入的任意类型的字符串并都认为是字符串类型返回 input只接受int类型或正规表达式类型的字符串

良思益友

#2 Created at ... [Delete] [Delete and Lock User]

我用input也可以,没有报错为什么呢

梦毁城

#3 Created at ... [Delete] [Delete and Lock User]

这是python 3教程,你用的python 2,唉。。。


  • 1

Reply