首页 \ 问答 \ python这段程序中a=self.[:]是什么意思 self一般用法是啥

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关键字,表示当前对象。

再看看别人怎么说的。

相关问答

更多
  • 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.
  • 修饰器,decorator,参见PEP 318: http://www.python.org/dev/peps/pep-0318/
  • Python index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,该方法与 python find()方法一样,只不过如果str不在 string中会报一个异常。 功能:从列表中找出与某个元素匹配的第一个匹配项的位置 index()方法语法: str.index(str, beg=0, end=len(string)) str -- 指定检索的字符串 beg -- 开始索引,默认为0。 end -- 结束索引,默认为字符 ...
  • 修饰器,decorator,参见PEP 318: http://www.python.org/dev/peps/pep-0318/
  • self表示实例自身 a=self[:]就是superList[:]
  • 用例子来说吧: This bottle is not so much as that one .这只瓶子的水没有那只那么多。
  • 第一:可用来在子类构造函数中调用父类的构造函数,且必须是第一句 如: 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 if else if else 或者 if else 或者 if if 或者 if else if 这几种形式都是正确的
  • 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 ...

相关文章

更多

最新问答

更多
  • 在csproj中使用appdata环境变量(Use appdata environment variable in csproj)
  • 从背景返回后,Skobbler Map崩溃(Skobbler Map crashes after returning from background)
  • 如何保持对绑定服务的轮询?(How to keep polling a bound service?)
  • ASP.NET单选按钮jQuery处理(ASP.NET radio button jQuery handling)
  • Linux上的FORTRAN图形库(FORTRAN graphic library on Linux)
  • 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))
  • 功能包装避免重复(wrap of functions avoid duplicating)
  • Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())
  • 无法使用phonegap 2.4在Android上播放录音(unable to play audio recordings on android using phonegap 2.4)
  • VS2015 + Resharper:不要使用C#6(VS2015 + Resharper: Don't use C#6)
  • 大学电脑四级对初学者来说要多久能过
  • 特殊字符删除?(Special characters remove?)
  • Android视频教程现在网上的都比较零散呢?有些太坑爹了,感觉老师就是在想当然的讲
  • 计算同一个表中不同行之间的差异[重复](Calculate delta's between different rows in same table [duplicate])
  • Javaweb开发,技术路线是什么?该怎么写?
  • JavaScript只在php代码中执行一次(JavaScript only executes once inside php code)
  • 不兼容的字符编码:ASCII-8BIT和UTF-8(incompatible character encodings: ASCII-8BIT and UTF-8)
  • Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
  • 为具有瞬态scala依赖性的spring-xd项目优化gradle(Optimize gradle for spring-xd project with transient scala dependency)
  • 如何才能在Alpha测试模式下发布我的应用程序?(How can I publish my app in Alpha test mode only?)
  • “没有为此目标安装系统映像”Xamarin AVD Manager(“No system images installed for this target” Xamarin AVD Manager)
  • maven中的Scalatest:JUnit结果(Scalatest in maven: JUnit results)
  • 使用android SDK将文件直接上传到存储桶中的文件夹(Upload a file directly to a folder in bucket using android SDK)
  • 是否应将plists导入CoreData?(Should plists be imported to CoreData?)
  • java.lang.reflect.InvocationTargetException JavaFX TableView(java.lang.reflect.InvocationTargetException JavaFX TableView)
  • 根据唯一列值动态创建多个子集(Dynamically create multiple subsets based on unique column values)
  • 使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
  • 嵌套的模板可能性(Nested template possibilities)
  • 任何方式在iOS7 +上以编程方式打开蓝牙(Any way to turn on bluetooth programmatically on iOS7+)
  • 如何为给定的SQL查询编写JPA查询(How I can write JPA query for given SQL query)