Python bytes()関数
例
4バイトの配列を返します。
x = bytes(4)
定義と使用法
このbytes()
関数はbytesオブジェクトを返します。
オブジェクトをバイトオブジェクトに変換したり、指定したサイズの空のバイトオブジェクトを作成したりできます。
bytes()
と
の違いはbytearray()
、
bytes()
変更できないオブジェクトを返すことと、変更
bytearray()
できるオブジェクトを返すことです。
構文
bytes(x, encoding, error)
パラメータ値
Parameter | Description |
---|---|
x | A source to use when creating the bytes object. If it is an integer, an empty bytes object of the specified size will be created. If it is a String, make sure you specify the encoding of the source. |
encoding | The encoding of the string |
error | Specifies what to do if the encoding fails. |