Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
第一:
for i in range(4): return (1 << i)
第二个:
for i in range(4): return (2^i)
有人可以解释为什么两者之间有区别吗?
因为幂语法**不是^:
**
^
>>> [2**i for i in range(4)] [1, 2, 4, 8] >>> [1 << i for i in range(4)] [1, 2, 4, 8]
注意:^(hat) 是按位异或。