简体   繁体   中英

What does this code do in Python?

I'm learning Python and ran into some code that has this line...

self.clear()

I am curious as to what it would do and why would someone need to do this?

That line calls the clear method on the current object. What the clear method actually does depends on what class this code is inside.

If you found it inside the function, that looked like:

def __parse(self,filename):

then you will probably find something similar to this:

def clear(self):

If you find it, there's the code, that will be executed within self.clear()

抱歉,如果它不是清除的,但我只是找到了clear()的代码...所有操作都是在为它分配新值之前清除了UserDict对象。...我误解了代码,并以为编写者实际上正在删除当前对象....无论如何找到答案....感谢帮助人员....我将来会更加谨慎地询问我如何表达我的问题,尤其是首先不要问些什么。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM