Why does a range have the function “count”?

前端 未结 1 1148
别跟我提以往
别跟我提以往 2021-01-14 09:35

Unless I\'m mistaken, a range can only include unique numbers. So, a number could be in it or not.

I guess only if we want to pass a range as one of many accepted t

相关标签:
1条回答
  • 2021-01-14 10:34

    Because range() objects conform to the Sequence ABC, and that ABC has a .count() method.

    In other words, it is there for completeness sake, so that the object qualifies as a sequence.

    It doesn't have to go across the whole range as it is easy enough to calculate if the number is part of the sequence, see Why is `1000000000000000 in range(1000000000000001)` so fast?

    0 讨论(0)
提交回复
热议问题