Are there any uses of the empty tuple in Python?

前端 未结 3 1864
南旧
南旧 2020-12-18 18:25

Is there any other purpose (besides being there because it needs to be) the empty tuple may have? Or: what would you use the empty tuple for? If anything. I just can\'t find

3条回答
  •  情书的邮戳
    2020-12-18 19:02

    Here's when.

    def tuple_of_primes_less_than( n ):
        if n <= 2: return ()
        else:
            x, p = set( range(2,n) ), 2
            while p <= max(x):
                for k in range(2,int(2+math.sqrt(p))):
                    x.discard(k*p)
                p += 1
            return tuple( sorted( x ) )
    

提交回复
热议问题