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
| Name | Type | Description |
|---|---|---|
| s | str | The input string to be shortened |
| maxlen | int = 128 | The maximum character length allowed before truncation occurs |
| suffix | str = '...' | The string appended to the end of the text if it exceeds the maximum length |
Returns
| Type | Description |
|---|---|
str | The truncated string ending at the last complete word before the limit, appended with the specified suffix |