简体   繁体   English

当我使用 function 时,为什么我的 python 3 输入需要引号

[英]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.

相关问题 为什么我的 python 输入 function 要求输入两次? - Why does my python input function asks for input twice? Python:为什么Pool.map()在尝试使用其map函数的输入参数时会挂起? - Python: Why does Pool.map() hang when attempting to use the input arguments to its map function? 为什么 python 3 在我的代码中使用 test.json 时告诉我没有这样的文件或目录 - Why does python 3 tell me that there is no such file or directory when I use test.json in my code 为什么当我导入 pynput 并使用它时,它会删除我的 python 文件? - Why does when I import pynput and use it it deletes my python file? 当我尝试使用 OOP 和类时,为什么我的代码在 python 中显示 NameError? - Why does my code show NameError in python when I try to use of OOP and classes? 是否有 function 提供输入选项? 我正在运行 Python3,当我在输入中使用 $ 时出现 ValueError 。 这是我的第一个 Python 脚本 - Is there a function to give options for input? I am running Python3, I get a ValueError when I use the $ in my input. This is my first Python script 当我从目录外部导入此函数时,为什么我的python import语句失败? - Why does my python import statement fail when I import this function from outside the directory? 当我将其与Python 3 mod_wsgi应用程序一起使用时,为什么粘贴ErrorMiddleware会引发异常? - Why does Paste ErrorMiddleware throw an exception when I use it with my Python 3 mod_wsgi application? 为什么Python根据内容使用不同的引号来表示字符串? - Why does Python use different quotes for representing strings depending on their content? 当我使用“除了 FileNotFoundError”function 时,为什么 python 需要一个语句? “FileNotFoundError”不是已经声明了吗? - Why does python expects a statement when I use "except FileNotFoundError" function? Isn't the "FileNotFoundError" already a statement?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM