Truncate String

Truncate a string to a specified length with ellipsis.

Code

General
str[:length-3] + '...' if len(str) > length else str

Parameters

The string to truncate

Maximum length including ellipsis

Server

More Python Snippets