Python Bytes Methods

Beginner
6 min read
Updated: Nov 2026
42 method guides
Method index

About This Index

This page is the Python Bytes Methods index for the tutorial track. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Python 3 script with fixed data, and outputs show bytes exactly as print() displays them.

Learn what a bytes object is on the Bytes hub. Use this page when you need a specific method such as find(), split(), or decode().

Bytes in, bytes out.

Every argument must be a bytes-like object (b"...", bytearray, or memoryview); a str raises TypeError. Case and classification methods only understand ASCII, so bytes 128 to 255 are left alone. removeprefix() and removesuffix() need Python 3.9, and isascii() needs Python 3.7.

How to Call a Bytes Method

Put a dot after any bytes object, then the method name and its arguments. The result is a new object:

Python
packet = b"temp=21;hum=40"

print(packet.find(b";"))          # 7
print(packet.split(b";"))         # [b'temp=21', b'hum=40']
print(packet.upper())             # b'TEMP=21;HUM=40'
print(packet.decode("ascii"))     # temp=21;hum=40
print(packet.hex()[:6])           # 74656d

Python Bytes Methods Table

All method guides in this Python tutorial series (42 tutorials), grouped by purpose.

Case, replace, and translate

10 methods

Build changed copies: ASCII case conversion, replacing byte sequences, byte-by-byte translation tables, tab expansion, and zero padding.

MethodDescriptionTutorial
capitalize()Return a copy with the first byte uppercased and the rest lowercased (ASCII only).Try it
lower()Return a copy with all ASCII uppercase letters converted to lowercase.Try it
upper()Return a copy with all ASCII lowercase letters converted to uppercase.Try it
swapcase()Return a copy with ASCII uppercase and lowercase letters swapped.Try it
title()Return a copy where each word starts with an uppercase ASCII letter.Try it
replace()Return a copy with occurrences of one byte sequence replaced by another.Try it
translate()Map every byte through a 256-byte table and optionally delete some bytes.Try it
maketrans()Build a 256-byte translation table for translate().Try it
expandtabs()Replace tab bytes with spaces up to the next tab stop.Try it
zfill()Pad on the left with ASCII zero bytes, keeping a leading sign in front.Try it

Strip, trim, and pad

8 methods

Remove unwanted bytes from the ends, cut an exact prefix or suffix, and pad data to a fixed width for records and aligned output.

MethodDescriptionTutorial
strip()Return a copy with leading and trailing bytes from a set removed (whitespace by default).Try it
lstrip()Return a copy with leading bytes from a set removed (whitespace by default).Try it
rstrip()Return a copy with trailing bytes from a set removed (whitespace by default).Try it
removeprefix()Remove an exact prefix once if present (Python 3.9+).Try it
removesuffix()Remove an exact suffix once if present (Python 3.9+).Try it
center()Center the bytes in a field of a given width using a fill byte.Try it
ljust()Left-justify the bytes in a field, padding on the right with a fill byte.Try it
rjust()Right-justify the bytes in a field, padding on the left with a fill byte.Try it

Split and join

6 methods

Break bytes into fields, lines, or head and tail pieces, and glue a list of bytes objects back together with a separator.

MethodDescriptionTutorial
split()Split bytes into a list of bytes using a separator or runs of whitespace.Try it
rsplit()Split bytes from the right, so maxsplit keeps the leftmost part together.Try it
splitlines()Split bytes into lines at \n, \r\n, and \r boundaries.Try it
partition()Split at the first separator into a 3-tuple: before, separator, after.Try it
rpartition()Split at the last separator into a 3-tuple: before, separator, after.Try it
join()Concatenate an iterable of bytes-like objects with this bytes as the separator.Try it

Classification checks

8 methods

True or False tests for ASCII letters, digits, whitespace, case, and title case. Bytes 128 to 255 never count as letters or digits.

MethodDescriptionTutorial
isalnum()True if all bytes are ASCII letters or digits and there is at least one byte.Try it
isalpha()True if all bytes are ASCII letters and there is at least one byte.Try it
isascii()True if every byte is in the ASCII range 0-127; True for empty bytes.Try it
isdigit()True if all bytes are ASCII digits 0-9 and there is at least one byte.Try it
islower()True if there is at least one ASCII lowercase letter and no ASCII uppercase letters.Try it
isspace()True if all bytes are ASCII whitespace and there is at least one byte.Try it
istitle()True if the bytes are title-cased: each ASCII word starts uppercase and continues lowercase.Try it
isupper()True if there is at least one ASCII uppercase letter and no ASCII lowercase letters.Try it

Convert to text and hex

3 methods

Turn bytes into a str with an encoding, show them as a hex string, and parse a hex string back into bytes.

MethodDescriptionTutorial
decode()Decode bytes into a str using an encoding such as UTF-8.Try it
hex()Return a str of two hex digits per byte, with an optional separator.Try it
fromhex()Class method: build bytes from a string of hex digits.Try it

Frequently Asked Questions

They are the methods you call on a bytes object with dot notation, such as data.find(b"x"), data.split(b","), or data.decode("utf-8"). Each one returns a result and leaves the original bytes unchanged.
This index lists 42 guides, from capitalize() to zfill(), grouped into searching, case and translation, stripping and padding, splitting and joining, classification checks, and conversion.
No. Arguments must be bytes-like objects such as b"abc", bytearray, or memoryview. Passing a str like "abc" raises TypeError, so write b"abc" or encode the text first.
Yes. bytearray has every method listed here. Methods that build new data, such as upper() or replace(), return a bytearray when called on a bytearray.
Read the Python Bytes hub first. Then open find(), split(), strip(), decode(), and hex() from the tables below.

Start with capitalize()

Open the first guide in the list and work your way through the bytes methods.

capitalize() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful