书山有路勤为径,学海无涯苦作舟。 知识改变命运,行动创造未来。

Python面向对象编程

面向对象编程介绍

类和对象

  • 创建类
  • 实例化
  • self参数
  • 类变量
  • 实例变量
#first class

class Car:
    brand = "baoma"
    color = "red"

    def run(self,s):
        print("当前车速为:",s,"km/h")


test = Car()

print(test.brand)
test.color = "blue"
print(test.color)

test.run(60)