python_类与对象学习笔记

class Phone:

    #手机属性===>类属性
    # color='black'
    # price=4500
    # brand='oppo'
    # size='5.5'

    #参数化-魔法方法--初始化方法
    def __init__(self,color,price,brand,size=5):#我们是调用这个方法
        Phone.color=color# 类属性
        self.brand=brand# 对象属性
        self.size=size#尺寸

    # def __int__(self):#这是错的!!!!!

    #方法
    @classmethod
    def call(cls,tel_no):#打电话  类方法
        # print(cls.color)
        # print(cls.color)
        print('拨号:{},开始打电话'.format(tel_no))

    def send_message(self,tel_no,content='早上好'):#发送短信  对象方法
        print('给{},发送短信:{}'.format(tel_no,content))

    def watch_tv(self,*args):#看电视 *args 动态参数
        app=''
        for item in args:
            app+=item
            app+=''
        print('可以利用这些APP看电视,比如说:{}'.format(app))

    def take_shoot(self):#拍照
        self.color
        print('拍照')

    @staticmethod
    def add(a,b):#加法
        #静态方法--->工具方法  他不会调用任何类里面方法或者是属性
        print(a+b)

    def phone_info(self):#打印手机的相关信息
        print('颜色:{},品牌:{},价格:{},尺寸:{}'
              .format(self.color,self.brand,self.price,self.size))

猜你喜欢

转载自www.cnblogs.com/qiyuedetiankong/p/10778371.html