简体   繁体   中英

Why are these dots not equal in python?

I am working on texts and have the left dot from an input text and right dot typed from a keyboard. However, in Python, they are not being treated as equal.

'․' == '.'
Out[870]: False

What could be a possible reason, and how can I recreate the left dot using the keyboard?

["

The dot on the left is not<\/em> a period: it is a one dot leader<\/a> Unicode character.<\/i>

print('\u2024')

I would suggest going with str.maketrans in this case:

trans_table = str.maketrans({'․': '.'})
print(trans_table)

# prints `False`
print('․' == '.')

# now prints `True`
print('․'.translate(trans_table) == '.')
# or:
#   '․'.replace('․', '.') == '.'
["

Basically, the visual representation of characters as we perceive them has no meaning from a machine's perspective.<\/i>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM