上一页 1 ··· 36 37 38 39 40 41 42 43 44 ··· 80 下一页
摘要: # 售票员卖票 class Driver: _self=None _name= 'Driver_Jack'# 售票员的名字 _num= 0 # 售票员的业绩 def __new__(cls, *args, **kwargs): if cls._self is None :# 如果售票员这个类是空 c 阅读全文
posted @ 2023-07-16 21:04 胖豆芽 阅读(12) 评论(0) 推荐(0)
摘要: # 单例 class Driver: _self=None def __new__(cls, *args, **kwargs): if cls._self is None: cls._self=super().__new__(cls) return cls._self def __init__(se 阅读全文
posted @ 2023-07-15 21:01 胖豆芽 阅读(30) 评论(0) 推荐(0)
摘要: 理解单例前需要了解 init 和new 这是init的效果 # 认识new 和init class People(object): # def __new__(cls, *args, **kwargs): # print("执行了new") # return object.__new__(cls) 阅读全文
posted @ 2023-07-15 18:59 胖豆芽 阅读(9) 评论(0) 推荐(0)
摘要: import math class Circle: def __init__(self,r): self._r= r @property def area(self):#def >define 定义一个函数或方法 求面积 mianji=round(self._r**2*math.pi,2)# rou 阅读全文
posted @ 2023-07-15 15:26 胖豆芽 阅读(26) 评论(0) 推荐(0)
摘要: # 反射class Webb: def reg(self): print("欢迎进入注册页面") def login(self): print("欢迎进入登录页面") def home(self): print("欢迎进入主页") def about(self): print("欢迎进入关于页面") 阅读全文
posted @ 2023-07-15 14:09 胖豆芽 阅读(16) 评论(0) 推荐(0)
摘要: class MyClass: @classmethod def my_class_method(cls, arg1, arg2): # 使用cls参数访问类的属性和调用类的方法 print("This is a class method") print("Arguments:", arg1, arg 阅读全文
posted @ 2023-07-14 17:31 胖豆芽 阅读(47) 评论(0) 推荐(0)
摘要: 继承的示例:class Animal(object):# 父类 def run(self): print('Animal is running...') class Dog(Animal): def run(self):# 狗类 继承了 动物类 print('Dog is running...') 阅读全文
posted @ 2023-07-14 16:58 胖豆芽 阅读(8) 评论(0) 推荐(0)
摘要: 1 没有范围限制 在类外部可以更改类内部的属性值 # 但是,既然Student实例本身就拥有这些数据,要访问这些数据,就没有必要从外面的函数去访问, # 可以直接在Student类的内部定义访问数据的函数,这样,就把“数据”给封装起来了. # 这些封装数据的函数是和Student类本身是关联起来的, 阅读全文
posted @ 2023-07-14 16:23 胖豆芽 阅读(20) 评论(0) 推荐(0)
摘要: 1. # 理解类 class Student(object): pass bart= Student() # 变量bart指向的就是一个Student的实例,后面的0x10a67a590是内存地址,每个object的地址都不一样,而Student本身则是一个类 # print(bart)# <__m 阅读全文
posted @ 2023-07-14 15:20 胖豆芽 阅读(19) 评论(0) 推荐(0)
摘要: # 冒泡 最大的在最后面 def maopao(arr): # 列表的长度-1=最大下标 index_max=len(arr)-1 # 外层循环 for i in range(index_max): # 内存循环比大小 flag=False # 默认不需要交换 for x in range(inde 阅读全文
posted @ 2023-07-13 21:42 胖豆芽 阅读(13) 评论(0) 推荐(0)
上一页 1 ··· 36 37 38 39 40 41 42 43 44 ··· 80 下一页