【python随笔】python2和python3语法区别

输出 hello world

  • python:
    1
    print "hello world"
  • python3:
    1
    print("hello world")

整数除法

输出 1.5``

  • python:
    1
    3.0 / 2
  • python3:
    1
    3 / 2

输入语句

  • python:
    1
    raw_input('请输入年龄')
  • python3:
    1
    input('请输入年龄')

创建类

  • python:
    1
    class ClassName(object):
  • python3:
    1
    class ClassName():

类的继承

父类为 Car, 子类为 ElectricCar

  • python:
    1
    2
    3
    class ElectricCar(Car):
    def __init__(self, make, model, year):
    super(ElectricCar, self).__init__()
  • python3:
    1
    2
    3
    class ElectricCar(Car):
    def __init__(self, make, model, year):
    super().__init__()