Is there any case where len(someObj) does not call someObj's __len__ function?

前端 未结 5 1485
挽巷
挽巷 2020-12-06 02:45

Is there any case where len(someObj) does not call someObj\'s __len__ function?

I recently replaced the former with the latter in a (sucess

5条回答
  •  佛祖请我去吃肉
    2020-12-06 03:12

    If __len__ returns a length over sys.maxsize, len() will raise an exception. This isn't true of calling __len__ directly. (In fact you could return any object from __len__ which won't be caught unless it goes through len().)

提交回复
热议问题