访次: AmazingCounters.com 次

二、Python-----用户交互

1.用户交互

Python 3.0的写法

name = input("Please input your name:")

Python 2.0的写法

name = raw_input("Please input your name:")

Python2.7的写法

name = raw_input("Please input your name:")

=====================================

name = input("Please input your name:")

会提示NameError: name 'xxxxx' is not defined

这就说明了2.7中 的 input 输入的是什么格式就会被解释器当做什么格式

当你输入数字 就会被认为数字,当你输入的是变量(不加引号)就会被认为是变量,当你输入的是字符串(加引号)就会被认为是字符串.

 

所以在3.0中去烦从简 把raw_input取消了.

python2              Python3

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

 

 

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

 

posted @ 2016-01-05 22:29  IT老登  阅读(214)  评论(0编辑  收藏  举报
访次: AmazingCounters.com 次