SEMrush

Built-in Functions In Python - Letter B

   bin(x)

Converts an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an__index__() method that returns an integer.

class bool([x])

Returns a Boolean value, i.e. one of True or Falsex is converted using the standard truth testing procedure. If x is false or omitted, this returnsFalse; otherwise it returns True. The bool class is a subclass of int (see Numeric Types — int, float, complex). It cannot be subclassed further. Its only instances are False and True 

    class bytearray([source[encoding[errors]]])

Returns a new array of bytes. The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has, see Bytes and Bytearray Operations.
The optional source parameter can be used to initialize the array in a few different ways:
  • If t is a string, you should also encode(and optionally, errors) parameters; bytearray() then converts the string to bytes usingstr.encode().
  • If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents of the array.
  • If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.
  • If it is an integer, the array will have that size and will be initialized with null bytes.
Without an argument, an array of size 0 is created.


class bytes([source[encoding[errors]]])

Returns a new “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256bytes is an immutable version ofbytearray – it has the same non-mutating methods and the same indexing and slicing behavior.
Accordingly, constructor arguments are interpreted as for bytearray().
Bytes objects can also be created with literals.




Comments