Python input && raw_input

#coding=utf-8
__author__ = 'baodong'

inp = input("Please Input ...")

print(type(inp))
print(inp)
# >>>123
# <type 'int'>
# 123
# >>>3.14
# <type 'float'>
# 3.14
# >>>2 ** 10
# <type 'int'>
# 1024
# >>>abc
# Traceback (most recent call last):
#   File "/Users/baodong/PycharmProjects/Learning/test0.py", line 4, in <module>
#     inp = input("Please Input ...")
#   File "<string>", line 1, in <module>
# NameError: name 'abc' is not defined
# >>>'abc'
# <type 'str'>
# abc

input()

接收表达式。字符串必须用引号包起来。
对数字有特殊处理。

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


#coding=utf-8
__author__ = 'baodong'

inp = raw_input("Please Input ...")

print(type(inp))
print(inp)
# >>>123
# <type 'str'>
# 123
# >>>3.14
# <type 'str'>
# 3.14
# >>>1+3
# <type 'str'>
# 1+3
# >>>abc
# <type 'str'>
# abc

raw_input()

“生input”
读一行并以string输出,不对表达式处理,字符串不需要引号。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值