Python2与Python3

1.了解python基本信息

python2.x:默认使用ASCII编码,python3.x:默认使用UTF-8编码
Python命令不使用分号(编码规范 PEP8),是严格按照缩进的语言

2.print的区别

python2中: print是一个语法结构,print ‘hello world’或者print “hello world”
Python2与Python3

python3中: print是一个函数,print(“hello world”)或者print(‘hello world’),单引号和双引号等效
python2使用’'或"",python3使用(’’)或("")
Python2与Python3

3.python中的显示

- 颜色

python脚本编写时,一般以.py结尾,告诉系统这是一个python文件(也可不以.py结尾)
以.py结尾的python脚本文件中print为蓝色字体,不以.py结尾的python脚本文件中print为黑色字体

- 中文的显示

python2不能显示中文字体
Python2与Python3
python2中加入#_coding:utf-8_声明后可显示中文
Python2与Python3

python3可显示中文
Python2与Python3

4.除法运算

python2的除法运算以整数型显示
Python2与Python3
python3的除法运算以浮点型显示
Python2与Python3

5.字符类型

pythob2的整型分为短整型(int)和长整型(long)
Python2与Python3
pythob3的整型只有int一种
Python2与Python3

6.input

python2中的raw_input() 与python3中的input() 功能一样,它会把用户输入的任何值都作为字符串来对待;而python2中的input不能读取非字符串
Python2与Python3
python3 中只有input(),并且把用户输入的任何值都作为字符串来对待
Python2与Python3

7.不等运算符

python2中的不等于运算符为!=和<>两种
Python2与Python3
python3中的不等于运算符为!=一种
Python2与Python3

相关文章:

  • 2021-11-02
  • 2021-05-24
  • 2021-11-02
  • 2021-11-02
  • 2021-11-02
  • 2021-11-02
  • 2022-02-16
猜你喜欢
  • 2021-11-20
  • 2022-02-22
  • 2022-02-04
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案