Bytearray Methods

bytearray.expandtabs()

Replace ASCII tab bytes with enough ASCII spaces to reach the next tab stop. Each non-tab byte advances the column by one, except LF and CR reset it to zero. Other control bytes do not reset the column. A nonpositive tab size deletes tabs. Column counting is by bytes, not Unicode display width. Returns a new bytearray.

Formal Syntax & Structure

python syntaxpython
data.expandtabs(tabsize=8)

Parameters & Attributes

NameTypeDescription
tabsizeintSpacing between tab stops, in byte columns; nonpositive removes tabs.

Return Value

bytearray

bytearray with tabs expanded into spaces.

Working Example

Example Snippetpython
print(bytearray(b'A\tB').expandtabs(4))print(bytearray(b'AB\tC\nX\tY').expandtabs(tabsize=4))print(bytearray(b'A\tB').expandtabs(0))
Python Reference