Free cookie consent management tool by TermsFeed The lower() method of bytearray class in Python | Pythontic.com

The lower() method of bytearray class in Python

Overview:

  • The lower() method of bytearray class creates a lowercase version of the bytearray contents and returns it. The method does not change the bytearray in-place. A bytearray in Python can hold ASCII and the bytes corresponding to values up-to 255. The uppercase ASCII values are translated to lowercase ones in the new bytearray.

The lower() method of bytearray in Python

  • If the use case is to get the lowercase copy of a Unicode sequence, the lower() method of the Python string class can be used. A string in Python is a mutable sequence of Unicode codepoints with a specified encoding.

Example:

# Example Python program that converts 
# a bytearray containing ASCII values to 
# corresponding uppercase values

# Create a mutable sequence of ASCII values
buffer = bytearray(b"HOW LONG IS FOREVER")
print(buffer)

# Convert uppercase from lowercase values
translated = buffer.lower()
print(translated)

Output:

bytearray(b'HOW LONG IS FOREVER')
bytearray(b'how long is forever')

 


Copyright 2025 © pythontic.com