python-????????????,python有什么用,?????????1
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
相关内容
- 聊聊 Python 发送邮件的几种方式,
- Python工具整合,为程序员和新手准备的 8 大 Python 工具
- 你需要了解的比较重要的Python概念,
- Python ?????????????????????,python有什么用,??????????
- python????????????__reduce__()?????????,pythonreduce函数,????????
- 2020年您应该知道的13个优秀Python库,
- 告别刷抖音!30秒一个Python小例子,总有一款适合你,
- 12个常用的IPython魔法命令,linux常用的20个命令
- 30个Python常用极简代码,拿走就用,
- 那些被低估的Python库,
评论关闭