python这段程序中a=self.[:]是什么意思 self一般用法是啥
class superList(list): def __sub__(self, b): a = self[:] # 这里,self是supeList的对象。由于superList继承于list,它可以利用和list[:]相同的引用方法来表示整个对象。 b = b[:] while len(b) > 0: element_b = b.pop() if element_b in a: a.remove(element_b) return a print superList([1,2,3]) - superList([3,4])
更新时间:2023-02-04 06:02
最满意答案
self表示实例自身 a=self[:]就是superList[:]
其他回答
self类似于Java/C++里的this关键字,表示当前对象。 再看看别人怎么说的。
相关问答
更多-
python编程中cmp()函数是什么意思?[2021-11-24]
cmp( x, y) Compare the two objects x and y and return an integer according to the outcome. The return value is negative if x < y, zero if x == y and strictly positive if x > y. 比较2个对象,前者小于后者返回-1,相等则返回0,大于后者返回1. -
Python中@是什么意思?[2022-02-06]
修饰器,decorator,参见PEP 318: http://www.python.org/dev/peps/pep-0318/ -
Python 中的index一般是什么意思,怎么个用法?[2023-01-03]
Python index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,该方法与 python find()方法一样,只不过如果str不在 string中会报一个异常。 功能:从列表中找出与某个元素匹配的第一个匹配项的位置 index()方法语法: str.index(str, beg=0, end=len(string)) str -- 指定检索的字符串 beg -- 开始索引,默认为0。 end -- 结束索引,默认为字符 ... -
Python中@是什么意思?[2022-04-02]
修饰器,decorator,参见PEP 318: http://www.python.org/dev/peps/pep-0318/ -
python这段程序中a=self.[:]是什么意思 self一般用法是啥[2023-02-04]
self表示实例自身 a=self[:]就是superList[:] -
not so much .... as 怎么用法[2022-04-09]
用例子来说吧: This bottle is not so much as that one .这只瓶子的水没有那只那么多。 -
JAVA中super()的用法?[2022-09-04]
第一:可用来在子类构造函数中调用父类的构造函数,且必须是第一句 如: class aa() { aa(); aa(int a,int b); } class b extend aa { b() {super();} b(int a,int b){super(a,b);} } 第二:可用来调用子类隐藏的父类方法或变量 如: class a { int a; int fa(); } class b extends a {int a; int fa(); int fb(int c,int d) { super.a ... -
if else if else 的用法[2023-01-14]
if表示判断,else可有可无,下面我举几个正确例子 例如 if else if else if else 或者 if else 或者 if if 或者 if else if 这几种形式都是正确的 -
are /is was were用法[2022-12-24]
A B B both 表示两着都… 是个副词,也可以做代词,例: 副词:We are both students. 代词:Both of us are students. 它的否定形式是neither 词性和both一样,例: 副词:We are neither STUDENT, 注意是单数名词. 代词:Neither of us IS a student 同样注意也是单数 one of +名词复数 而后面的谓语动词要用单数 因为中心语是 one of thunderstorms是雷雨得意思,用复数 如果用 ... -
每当你必须越过路径时,你会打电话给acquire ,当你有越过路径时,你可以打电话给release Semaphore semaphore= new Semaphore(No of Lizards that can cross the road at a time); sagoToMonkeyIsSafe();<-- semaphore.acquire(); as crossing the path start // cross path to monkey grass crossedOverToMo ...