all Python 3Byte sequencesfunction
bytes.rpartition
bytes — split and join
Split at the last separator into (head, sep, tail).
Syntax
b.rpartition(...)
When the separator is missing, the two empty pieces come first and the original data lands in the third element — mirroring partition, where the whole value stays in the first. So name, _, ext = ... on input without a dot leaves name empty and puts everything into ext; check the middle element before trusting the split.
Examples
print(b'a=b=c'.rpartition(b'=')) # → (b'a=b', b'=', b'c')
print(b'a=b=c'.partition(b'=')) # → (b'a', b'=', b'b=c')
name, _, ext = b'archive.tar.gz'.rpartition(b'.')
print(ext) # → b'gz'
print(b'abc'.rpartition(b'=')) # → (b'', b'', b'abc')
print(b'abc'.rpartition(b'')) # → ValueError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy