randomString.decode( "utf-8")とstr(randomString、 "utf-8")の違いは何ですか?
私は彼らが同じことを見るが、私がそれらを試してみると、彼らは異なっていることが分かる!randomString.decode( "utf-8")とstr(randomString、 "utf-8")の違いは何ですか?
>>> randomString = "Hello World"
>>> str(randomString)
\'Hello World'
>>> randomString.decode("utf-8")
Traceback (most recent call last):
File "< input >", line 1, in
AttributeError: 'str' object has no attribute 'decode'
>>> randomString.encode()
b'Hello World'
>>> bString = randomString.encode()
>>> bString.decode()
'Hello World'
>>> str(bString)
"b'Hello World'"
と私は本当に、通常の文字列とバイト列の違いを理解していませんか? ヘルプplz!
'randomString = "Hello Worldのをěščřž" お試しください。 print(randomString.encode( "utf-8")) 'で非ASCII文字の一部を使用します。注** encode **は文字列からバイトへの変換で、** decode **は文字列からバイトへの変換です。 – JosefZ
私がBytes:__b'Hello World \ xc4 \ x9b \ xc5 \ xa1 \ xc4 \ x8d \ xc5 \ x99 \ xc5 \ xbe '__ ,,を与えてもokですが、私はデコード部分と混乱しています... str (randomBytes、 "utf-8")はrandomBytes.decode( "utf-8")のようにデコードしますか? –
'print(str(randomString.encode()、" utf-8 ")== randomString.encode()。decode())'返す**本当の**だからあなたは何を求めていますか? – JosefZ