python-????????????,python有什么用,?????????1


?????????

1.???????????????

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

2. ????????????-????????????1?????????

3. ???????????????????????????1???__init__??????

# ???????????? ?????????????????????????????????????????? ????????????(?????????????????????????????????)# ???????????? ??????????????????__init__??????(????????????????????????????????????????????????)(name=?????? age=20)# ?????????????????????(??????????????????)class Person(object):    # ?????????????????????  ??????????????????????????????    __instance = None    # ????????????????????? ???????????????????????????init??????    __is_first = True    # ????????????    # ??????new?????? ???????????????????????????????????????????????????    def __new__(cls, *args, **kwargs):        # ??????????????????????????????????????????        if not cls.__instance:   # ???????????????????????????            cls.__instance = object.__new__(cls)   # ????????????????????????        return cls.__instance  # ????????????????????????    def __init__(self, name, age):        # ????????????????????????        if Person.__is_first:            # ????????????            self.name = name            self.age = age            # ???????????????is_first ???False            Person.__is_first = False# ????????????xiaoming = Person("??????", 20)xiaohong = Person("??????", 21)xiaoyang = Person("??????", 22)print(xiaoming.name, xiaohong.name, xiaoyang.name)  # ?????? ?????? ??????# num = None# # ????????????none ????????????# if not num:#     print("??????")# ??????????????????class HMTest(object):    def my_func(self, a, b):        return a + b# ???????????? ?????????????????????????????? ??????1000??? ????????????999?????????# ????????????# ?????????????????????# hm = HMTest()# hm.my_func(10, 20)# ??????????????????

???

python-????????????

?????????

???????????????https://www.cnblogs.com/peiya/p/13290004.html

评论关闭