热线电话:13121318867

登录
2019-01-19 阅读量: 793
input与raw_input有什么区别(1)

问题描述:

在Python 2.x中有两种常见的接收输入的方法:

  1. 使用input()函数:此函数按原样获取输入的值和类型,而不修改任何类型。
  2. 使用raw_input()函数:此函数显式地将您提供的输入转换为类型字符串

那么,这两者之间有什么区别呢?

问题解决:

在input()函数中给出字符串输入时,我们必须用双引号括起来。raw_input()中不需要这样做》

让我们使用以下程序来确定两者之间的区别:

# Python 2.x program to show differences between

# input() and rawinput()function

# 3 inputs using raw_input() function,

# after which data type of the value

# entered is displayed

s1 = raw_input("Enter input to test raw_input() function: ")

print type(s1)

322.0746
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子