[英]Why does my python 3 input requires quotes when i use the function
I am new to programming and i have a problem.我是编程新手,我有一个问题。 When i use input function for my program, it wants me to enter my input with quotes.当我为我的程序使用输入 function 时,它希望我输入带引号的输入。 I am kind of sure that i am using python3 because other functions are running in the form of python3 codes.我有点确定我正在使用 python3,因为其他函数以 python3 代码的形式运行。 For example my print function is working like: print("Hello") instead of print "Hello"例如我的 print function 的工作方式是: print("Hello") 而不是 print "Hello"
I don't know what's wrong with input() function.我不知道 input() function 有什么问题。 Can someone please help me?有人可以帮帮我吗?
I am using MacOS version 10.14.6 and i am using SublimeText as my text editor我使用的是 MacOS 版本 10.14.6,并且我使用 SublimeText 作为我的文本编辑器
Update: I figured it out.更新:我想通了。 Thank you all for answering.谢谢大家的回答。 With the help of your answers i realized that i was using python 2.x.在您的回答的帮助下,我意识到我正在使用 python 2.x。 The problem was with my SublimeText build and i was able to find the problem!问题出在我的 SublimeText 版本上,我能够找到问题所在!
In Python 3, you take input using input()
function.在 Python 3 中,您使用input()
function 获取输入。 By default, when you provide any input to Python 3 using input()
method it will consider it of type String
.默认情况下,当您使用input()
方法向 Python 3 提供任何输入时,它会将其视为String
类型。 If you want to take an Integer
as input you need to mention int(input())
and then by using type()
method you can check its type.如果您想将Integer
作为输入,您需要提及int(input())
,然后使用type()
方法可以检查其类型。
i don't know if i'm understand correctly, but input()
is built-in function我不知道我是否理解正确,但是input()
是内置的 function
.For example to use it: .例如使用它:
var1 = input("Please enter anything: ")
print(var1)
output: output:
Please enter anything: our answer is here
our answer is here
This error only occur in py2 which is why I believe you are making use of Python 2. Try using raw_input()
.此错误仅发生在 py2 中,这就是为什么我相信您正在使用 Python 2。尝试使用raw_input()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.