上一页 1 2 3 4 5 6 7 8 9 10 ··· 44 下一页
摘要: class People(object): color = "yellow" __age = 30 #私有属性 def think(self): self.color = "black" print("I am a %s" %self.color) print(self.__age) def __t 阅读全文
posted @ 2022-10-22 19:56 ty1539 阅读(16) 评论(0) 推荐(0) 编辑
摘要: #_*_ encoding: utf-8 _*_ @author: ty hery 2018/9/6 def printStar(intNum): s = "*" spaceLength = intNum blockCount = int(intNum / 2 + 1) for i in range 阅读全文
posted @ 2022-10-22 11:03 ty1539 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 这种变形的特点: 1,在类外部无法直接obj.__AttrName 2,在类内部可以直接使用:obj.__AttrName 3,子类无法覆盖父类__开头的属性 0, class A: '类的封装啊' __x = 1 # _A__x = 1 print('你去吃啥饭0000') def __init_ 阅读全文
posted @ 2022-10-19 08:29 ty1539 阅读(37) 评论(0) 推荐(0) 编辑
摘要: 问题:1.)上面的__init__函数中,加*句我不写,为啥不可以?不理解里面怎么传递。。。初始化的时候不是先在内部调用了__init__,生成了L了吗? 下面函数不能用这里的L,甚至是 a,b这些变量? 2.)如果要让 init 下的变量传到别的函数,是不是一定要用self.var这种形式? 我自 阅读全文
posted @ 2022-10-19 08:16 ty1539 阅读(16) 评论(0) 推荐(0) 编辑
摘要: '''一般来说,要使用某个类的方法,需要先实例化一个对象再调用方法。 而使用@staticmethod或@classmethod,就可以不需要实例化,直接类名.方法名()来调用。 这有利于组织代码,把某些应该属于某个类的函数给放到那个类里去,同时有利于命名空间的整洁。 既然@staticmethod 阅读全文
posted @ 2022-10-16 20:58 ty1539 阅读(17) 评论(0) 推荐(0) 编辑
摘要: class TSSS(): def f1(self): print('from TSSS') class SSS(TSSS): def f1(self): print('from SSS') class SS(): def f1(self): print('from SS') class S(SSS 阅读全文
posted @ 2022-10-16 20:52 ty1539 阅读(13) 评论(0) 推荐(0) 编辑
摘要: def test1(): l = [] for i in range(1000): l = l + [i] def test2(): l = [] for i in range(1000): l.append(i) def test3(): l = [i for i in range(1000)] 阅读全文
posted @ 2022-10-12 08:24 ty1539 阅读(14) 评论(0) 推荐(0) 编辑
摘要: >>> s = 'RUNOOB' >>> repr(s) "'RUNOOB'" >>> dict = {'runoob': 'runoob.com', 'google': 'google.com'}; >>> repr(dict) "{'google': 'google.com', 'runoob' 阅读全文
posted @ 2022-08-14 23:22 ty1539 阅读(39) 评论(0) 推荐(0) 编辑
摘要: import itertools a = range(1, 5) y = list(itertools.permutations(a, 3)) print(y) 输出: [(1, 2, 3), (1, 2, 4), (1, 3, 2), (1, 3, 4), (1, 4, 2), (1, 4, 3) 阅读全文
posted @ 2022-08-14 23:14 ty1539 阅读(258) 评论(0) 推荐(0) 编辑
摘要: class ToDictMixin(object): def to_dict(self): return self._traverse_dict(self.__dict__) # 具体的实现代码写起来也很直观:我们只需要用hasattr函数动态地访问属性、isinstance函数动态地检测对象类型, 阅读全文
posted @ 2022-08-13 15:09 ty1539 阅读(67) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 44 下一页