Python3-string-decode
提供:Dev Guides
Python 3-String decode()メソッド
説明
- decode()*メソッドは、エンコード用に登録されたコーデックを使用して文字列をデコードします。 デフォルトはデフォルトの文字列エンコーディングです。
構文
以下は* decode()*メソッドの構文です-
Str.decode(encoding = 'UTF-8',errors = 'strict')
パラメーター
- encoding -これは使用されるエンコーディングです。 すべてのエンコーディングスキームのリストについては、https://docs.python.org/library/codecsl#standard-encodings [Standard Encodings。]にアクセスしてください。
- エラー-これは、異なるエラー処理スキームを設定するために指定できます。 エラーのデフォルトは「strict」です。つまり、エンコードエラーはUnicodeErrorを発生させます。 他の可能な値は、「ignore」、「replace」、「xmlcharrefreplace」、「backslashreplace」、およびcodecs.register_error()を介して登録されたその他の名前です。
戻り値
デコードされた文字列。
例
#!/usr/bin/python3
Str = "this is string example....wow!!!";
Str = Str.encode('base64','strict');
print "Encoded String: " + Str
print "Decoded String: " + Str.decode('base64','strict')
結果
上記のプログラムを実行すると、次の結果が生成されます-
Encoded String: b'dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE='
Decoded String: this is string example....wow!!!