is not used to determine whether two objects are the same object is judged by id () function takes the object address. python caches small integer, and string contains only alphanumeric and underscores. So for these values when, it is determined to True.
>>> a = 10 >>> b = 10 >>> a is b True >>> a = 257 >>> b = 257 >>> a is b False >>> a = "123" >>> b = "123" >>> a is b True >>> a = "urifsdka" >>> b = "urifsdka" >>> a is b True >>> a = "siru289ur2jfkjhsfa98uasfjh293ruhfkjsdhf9w28u3rhhskfj_fhihfiwehfkjsahfushf" >>> b = "siru289ur2jfkjhsfa98uasfjh293ruhfkjsdhf9w28u3rhhskfj_fhihfiwehfkjsahfushf" >>> a is b #对于很长的字符串也是如此 True >>> a = "a b"# Spaces False >>> A B IS >>> B = "ab &" >>> A = "ab &" # spaces False >>> A B IS >>> B = "A B" >>> A = 10.0 >>> b = 10.0 >>> a is b False >>> a = "a#b" >>> b = "a#b" >>> a is b False >>>