Python

Python Menu

Python

Python bytearray() Function - Definition, Syntax, Parameters, Examples

Definition

The bytearray() function returns a bytearray object.

It can convert objects into bytearray objects, or create empty bytearray object of the specified size.

Syntax

bytearray(x, encoding, error)

Parameters

Parameter Description
x A source to use when creating the bytearray object.
If it is an integer, an empty bytearray object of the specified size will be created.
If it is a String, make sure to specify the encoding of the source.
encoding The encoding of the string
error Specifies what to do if the encoding fails.

Examples

x = bytearray(8) print(x)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods