Python3-string-encode
提供:Dev Guides
Python 3-String encode()メソッド
説明
- encode()*メソッドは、文字列のエンコードされたバージョンを返します。 デフォルトのエンコーディングは、現在のデフォルトの文字列エンコーディングです。 エラーは、異なるエラー処理スキームを設定するために与えられます。
構文
以下は* encode()*メソッドの構文です-
str.encode(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
import base64
Str = "this is string example....wow!!!"
Str = base64.b64encode(Str.encode('utf-8',errors = 'strict'))
print ("Encoded String: " , Str)
結果
上記のプログラムを実行すると、次の結果が生成されます-
Encoded String: b'dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE='