Issue 28481: Weird string comparison bug (original) (raw)
Issue28481
Created on 2016-10-20 04:03 by mingrammer, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (2) | ||
---|---|---|
msg279011 - (view) | Author: MinJae Kwon (mingrammer) * | Date: 2016-10-20 04:03 |
I found bug i think about string comparison > var1 = 'aa' > var1 is 'aa' # This is True But if the string literal has special chacter (e.g., colon), the comparison results in False > var2 = ':bb' > var2 is ':bb' # This is False Check it please. | ||
msg279014 - (view) | Author: Eryk Sun (eryksun) * ![]() |
Date: 2016-10-20 04:33 |
Interning of strings is an implementation detail for the efficient storage of variable and attribute names. A string with ':' in it cannot be a variable or attribute name and thus is not interned. But you don't need to know which strings are interned or why they're interned because correct Python code should never compare strings by identity. Use an equality comparison, e.g. (var2 == ':bb'). Generally identity comparisons are of limited use in Python, such as checking for a singleton object such as None. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:38 | admin | set | github: 72667 |
2016-10-20 04:33:01 | eryksun | set | status: open -> closednosy: + eryksunmessages: + resolution: not a bugstage: resolved |
2016-10-20 04:03:48 | mingrammer | create |