[英]How to compare unicode with string in python
我嘗試用字符串編碼base64后比較值。 但是encode64
不等於Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=
為什么不等於?
import hashlib
hash_object = hashlib.sha256(b'Test')
hex_dig = hash_object.hexdigest()
encode64 = hex_dig.decode('hex').encode('base64')
print(encode64)
if encode64 == 'Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=' :
print("Hello")
產量
Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=
它不會打印Hello。
在encode64變量的末尾有一個“ \\ n”。 你可以做
if encode64.strip() == 'Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=' :
print("Hello")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.