In code, list.clear doesn't throw error - it's just ignored

DFS nospam at dfs.com
Sun Nov 13 16:28:39 EST 2022


In code, list.clear is just ignored.
At the terminal, list.clear shows
<built-in method clear of list object at 0x000001C9CFEC4240>


in code:
x = [1,2,3]
x.clear
print(len(x))
3

at terminal:
x = [1,2,3]
x.clear
<built-in method clear of list object at 0x000001C9CFEC4240>
print(len(x))
3


Caused me an hour of frustration before I noticed list.clear() was what 
I needed.

x = [1,2,3]
x.clear()
print(len(x))
0



More information about the Python-list mailing list