python2和python3的区别

1,print:

python2中不加括号,python3中加括号

2,

python2:经典类/新式类           (经典类遵循深度优先的算法)

python3:新式类                           (新式类遵循的是c3算法)

3,编码

        字符串

     py2

        unicode      v=u"root"      本质上用unicode存储(万国码)

       (str/bytes)  v=u"root"      本质用字节存储

     py3

              str               v=u"root"      本质用unicode存储(万国码)

        bytes           v=u"root"       本质上用字节存贮

  编码

      python2     --assic码             #再puthon2中,因为默认使用assic码,所以再文件开头都写#-*- encoding:utf-8 -*-

      python3     --utf-8

4,输入,

python2:   raw_input()

python3:  input()

5,范围:

python2   range/xrange

python3              range(等于python2中的xrange,不会把生成的结果一次性输出)  (但是:lst(range(10))这种方式可以一次都打印出来)

6.除法

python2   3/2    地板除==1

python3    3/2      ==1.5

原文地址:https://www.cnblogs.com/zhuhaofeng/p/9614071.html