Skip to main content

truncate

Truncate text to a maximum number of characters.

def truncate(
s: str,
maxlen: int = 128,
suffix: str = '...'
) - > str

Truncate text to a maximum number of characters.

Parameters​

NameTypeDescription
sstrThe input string to be shortened
maxlenint = 128The maximum character length allowed before truncation occurs
suffixstr = '...'The string appended to the end of the text if it exceeds the maximum length

Returns​

TypeDescription
strThe truncated string ending at the last complete word before the limit, appended with the specified suffix