在Python 2.6中查看Queue.py,我发现这个构造我发现有点奇怪:
def full(self):
"""Return True if the queue is full, False otherwise
(not reliable!)."""
self.mutex.acquire()
n = 0 < self.maxsize == self._qsize()
self.mutex.release()
return n
Run Code Online (Sandbox Code Playgroud)
如果maxsize为0,则队列永远不会满.
我的问题是它如何适用于这种情况?如何0 < 0 == 0被认为是假的?
>>> 0 < 0 == 0
False
>>> (0) < (0 == 0)
True
>>> (0 < 0) == 0
True
>>> 0 < (0 == 0)
True
Run Code Online (Sandbox Code Playgroud) 该
is运营商不匹配变量的值,但这些实例本身.
它到底意味着什么?
我声明了两个变量命名x并y在两个变量中分配相同的值,但是当我使用is运算符时它返回false .
我需要澄清一下.这是我的代码.
x = [1, 2, 3]
y = [1, 2, 3]
print x is y #It prints false!
Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
>>> x = "google"
>>> x is "google"
True
>>> x = "google.com"
>>> x is "google.com"
False
>>>
Run Code Online (Sandbox Code Playgroud)
为什么会那样?
为了确保上述内容正确,我刚刚在Linux上测试了Python 2.5.4,2.6.5,2.7b2,Python 3.1和Linux上的Python 2.7b1.
看起来所有这些都是一致的,所以它是设计的.我错过了什么吗?
我发现,我的一些个人域名过滤脚本失败了.