其他分享
首页 > 其他分享> > 面向对象

面向对象

作者:互联网

1.面向对象概念

class Car:
    wheel = 4  #类变量,公共的
    country = "China"

    def __init__(self,color,name):
        print("生产了一个汽车!")
        #构造函数,类在实例化的时候,自动执行的函数
        self.color = color
        self.name = name
        self.fly()

    def __del__(self):    #函数或者变量前面加__是将其私有化
        print("汽车报废了!")
        #实例在销毁的时候自动执行的

    def fly(self):
        raise IndexError
        print("%s fly" % self.name)

    def say(self):
        print("我是一个小汽车,我的名字是%s,颜色是%s" %(self.name,self.color))
        print("我的国家是%s" % self.country)

# Car.say()
car1 = Car("红色","小黑汽车") #实例化   #car1是对象,
# car1.say()
# del car1
# print("!!!!!!!!!")

# del  car1
# car1.fly() # Car.fly(car1)
# fmz_car.fly()

# fmz_car = Car("红色","小黑汽车") #实例化
# # fmz_car.fly()   #使用函数前得实例化
# # fmz_car.say()
# Car.say()
# car2 = Car("青色","小青汽车") #实例化
# car2.say()

# fmz_car #对象、实例
# fmz_car2 = Car()
# fmz_car.fly()
# fmz_car.fly()
# fmz_car2.fly()

# import requests
# import logging
# l =  logging.Logger("xx")
#
#
# class MyRequest:
#     def get(self):
#         log.info("url,data,get")
#
# r = MyRequest(url,data,header,json,files)
# result = r.post()  # {}
# result = r.get()  # {}

  

标签:fly,fmz,变量,Car,self,面向对象,实例
来源: https://www.cnblogs.com/murongmengfei/p/14960711.html