记录下python学习中,钻牛角尖的一些脑残点

妖精的绣舞 提交于 2019-12-03 14:03:13
一、类的初始化:为什么用__init__(self)不直接写变量赋值1.用__init__(self)可控制属性变量2.__init__(self)自动执行代码,初始化类
class CocaCola:    formula = ['caffeine','sugar','water','soda']    def __init__(self):        for element in self.formula:            print('Coke has {}!'.format(element))    def drink(self):        print('Energy!')coke = CocaCola()二、类的超继承class father: def jiachan(self):     print(jin,yin,zhubao)class son(father): def jiachan(self): super(son,self).jiachan()三、list的删除list=[1,2,3,4,5]1.del按索引删除列表的元素,del.list[1]2.pop按索引取出元素的值可以赋值。无索引默认删除最后一个,list.pop[1]3.remove按值删除列表里的值,list.remove("1")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!