English 中文(简体)
“投入”和“产出”之间的差异 [复制]
原标题:Differences between `input` and `raw_input` [duplicate]
  • 时间:2010-09-27 03:07:32
  •  标签:
  • python

在一篇论文中,我读到,input raw_input之间存在差异。 我发现,这些职能的行为在3时发生了改变。 新行为是什么?

因此,在 p语中,译员是这样。

x = input()

修改错误,但如果我把它列入档案。 它不是吗?

最佳回答

在python 2.x中,raw_input(>> 回归缩略语和input(>>

>>> x = input()
"hello"
>>> y = input()
x + " world"
>>> y
 hello world 

在python 3.x中,input 已经报废,先前称为raw_input/code>的功能现为input。 因此,如果你想要使用旧功能,就必须人工打上<代码>compileeval

python2.x                    python3.x

raw_input()   --------------> input()               
input()  -------------------> eval(input())     

在3.x段中,上述会议与本届会议一样。

>>> x = eval(input())
 hello 
>>> y = eval(input())
x +   world 
>>> y
 hello world 
>>> 

因此,你可能会在解释者身上产生错误,因为你没有在你的投入上引述。 这一点是必要的,因为它进行了评估。 哪里出现名字错误?

问题回答

<>strong>input() vs original_input()

raw_input collects the characters the user types and presents them as a string. input() doesn t just evaluate numbers but rather treats any input as Python code and tries to execute it. Knowledgeable but malicious user could type in a Python command that can even deleted a file. Stick to raw_input() and convert the string into the data type you need using Python s built in conversion functions.

还有投入,但无法避免用户错误! 它希望有有效的“灰色”表述作为投入;如果该投入不具有巧妙效力,将提出“协同效应”。

其简单明了:

  1. raw_input() returns string values
  2. while input() return integer values

例:

1. 导言

x = raw_input("Enter some value = ")
print x

产出:

Enter some value = 123
 123 

2. 结 论

y = input("Enter some value = ") 
print y

产出:

Enter some value = 123
123

因此,如果我们履行<条码>x +x =。 产出为123

当我们履行<条码>y +=时, 产出为246





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签