Bell Aimsaard
Bell Aimsaard

Reputation: 505

How to compare unicode with string in python

I try to compare value after encode base64 with string. But encode64 does not equal to Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU= Why does not it equal ?

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")

Output

Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=

It does not print Hello.

Upvotes: 0

Views: 363

Answers (1)

CK Chen
CK Chen

Reputation: 664

There's a '\n' in the end of encode64 variable. You can do

if encode64.strip() == 'Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=' :
    print("Hello")

Upvotes: 3

Related Questions