Which is better in python, del or delattr?

后端 未结 8 1897
既然无缘
既然无缘 2020-12-12 11:08

This may be silly, but it\'s been nagging the back of my brain for a while.

Python gives us two built-in ways to delete attributes from objects, the del

8条回答
  •  再見小時候
    2020-12-12 11:27

    It's really a matter of preference, but the first is probably preferable. I'd only use the second one if you don't know the name of the attribute that you're deleting ahead of time.

提交回复
热议问题