homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Weird string comparison bug
Type: behavior Stage: resolved
Components: Unicode Versions: Python 3.7, Python 3.6, Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, ezio.melotti, mingrammer, vstinner
Priority: normal Keywords:

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) * (Python triager) 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:38adminsetgithub: 72667
2016年10月20日 04:33:01eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg279014

resolution: not a bug
stage: resolved
2016年10月20日 04:03:48mingrammercreate

AltStyle によって変換されたページ (->オリジナル) /