دالة بايثون بايت ()
مثال
إرجاع مصفوفة من 4 بايت:
x = bytes(4)
التعريف والاستخدام
تقوم 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. |