1、print
函数
Python3中print为一个函数,必须用括号括起来;Python2中print为class
Python 2 的 print 声明已经被 print()
函数取代了,这意味着我们必须包装我们想打印在小括号中的对象。
例如在python3中使用print "hello word! " 会报错,并给出建议:
2、raw_input()函数
通过input()解析用户的输入:Python3中input得到的为str;Python2的input的到的为int型,Python2的raw_input得到的为str类型
Python3中用input,Python2中用raw_input,都输入为str
在 Python 3 中已经解决了把用户的输入存储为一个 str 对象的问题。为了避免在 Python 2 中的读取非字符串类型的危险行为,我们不得不使用 raw_input() 代替。
#!/usr/bin/python
#coding=utf-8
print("你好,世界");
test = input("按下 enter 键退出,其他任意键显示...\n")
print(type(test))
#!/usr/bin/python
#coding=utf-8
print("你好,世界");
test = input("按下 enter 键退出,其他任意键显示...\n")
test2 =raw_input("and 按下 enter 键退出,其他任意键显示...\n")
print(type(test))
print(type(test2))
python3 已不支持raw_input() 函数