[Python] input() vs raw_input()
来源:互联网 发布:订餐源码 微信 java 编辑:程序博客网 时间:2024/05/21 19:30
Python版本:Python 2.7.13rc1
ex1.py :
name = input("What's your name? ")print("Nice to meet you " + name + "!")name2 = raw_input("What's your name? ")print("Nice to meet you " + name2 + "!")
input():
input会解释用户的输入。如果用户输入一个整数值,那么input()会返回一个整数值。在使用input()的时候,如果需要输入string, 那么需要在输入的时候加上引号。否则,Python会把这个输入当做变量来处理。
PS C:\pyex> python .\ex1.pyWhat's your name? JohnTraceback (most recent call last): File ".\ex1.py", line 1, in <module> name = input("What's your name? ") File "<string>", line 1, in <module>NameError: name 'John' is not defined
Note:尽量注意避免使用input(),因为会有安全问题。
raw_input():
raw_input不会解释输入,直接返回用户输入的内容,并不会有任何改变.。raw_input返回的是string类型,如果需要它返回整型,需要进行转换 x = int(raw_input()) 。
对比input()和raw_input()的输出结果
PS C:\pyex> python .\ex1.pyWhat's your name? "John\n"Nice to meet you John!What's your name? "John\n"Nice to meet you "John\n"!
0 0
- Python raw_input() vs input()
- [Python] input() vs raw_input()
- python 之 input() vs. raw_input()
- Python input() pk raw_input()
- 【python】raw_input() 和input()
- Python raw_input() 和input()
- python输入输出---input,raw_input
- python input()与raw_input()
- raw_input() 与 input() Python
- Python input和raw_input
- python input()与raw_input()
- python:input()和raw_input()
- python: input()、raw_input() 探究
- python input,raw_input函数
- python input()与raw_input()
- python input() 与raw_input()
- raw_input() 与 input() __ Python
- Python:raw_input 和 input用法
- C++Builder 动态生成定时器,创建定时器管理类
- HANDLE-->HANDLE_TABLE_ENTRY
- Android用百度地图实现定位
- jquery简单的拖动效果
- 从0开始学模拟挂(一)--找内存基址,包含原理 _ 脚本..._按键精灵论坛
- [Python] input() vs raw_input()
- 使用cocoaPods时出现一些问题的解决方法
- tar命令
- sublime text3搭建react native
- 函数指针简单实例
- typeof和instanceof区别
- HTML5移动端数据图表组件调研
- apache2.2配置https协议(key文件、crt文件、csr文件生成方法)
- 安卓开发设置控件边框