python中的input函数和raw_input函数的区别

input()和raw_input()函数的区别:

   首先,说明eval函数:eval函数的参数必须是字符串形式。eval函数是将字符串转换为算式运算。

       如:1. 参数为空,出错。

            2. 说明参数必须为字符串string对象。

            3.  eval函数将字符串转换为算式表达式求值,会在历史记录(局部空间,全局空间)寻找变量名的值。如x的值。

  其次,input函数。

          input函数是输入函数,如果输入的变量为字符串或字符,且该变量名在历史记录中有过赋值,则正确。 否则出错。   输入整数,正确。


  最后,raw_input函数,是将输入的变量以字符串存储起来。输入值都正确。不会出错。raw_input函数比input函数更通用。

eval ( expression [, globals [, locals ] ] )

The arguments are a Unicode or Latin-1 encoded string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object.

input([prompt])

Equivalent to eval(raw_input(prompt)).

If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.

If the readline module was loaded, then input() will use it to provide elaborate line editing and history features.

Consider using the raw_input() function for general input from users.

raw_input([prompt])

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example:

>>> s = raw_input('--> ')
--> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"

If the readline module was loaded, then raw_input() will use it to provide elaborate line editing and history features.


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值