Tag: 对象标识

将string与空格进行比较时,“是”运算符的行为不同

我已经开始学习Python(Python 3.3),我正在尝试is运算符。 我试过这个: >>> b = 'is it the space?' >>> a = 'is it the space?' >>> a is b False >>> c = 'isitthespace' >>> d = 'isitthespace' >>> c is d True >>> e = 'isitthespace?' >>> f = 'isitthespace?' >>> e is f False 似乎空间和问号使得行为有所不同。 这是怎么回事? 编辑:我知道我应该使用== ,我只是想知道为什么is行为。