【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__()

本文作者: haise
本文地址https://www.shifeng1993.com/2018/02/28/python_1/
版权声明: 转载请注明出处!