Python truncate a long string Python truncate a long string python python

Python truncate a long string


info = (data[:75] + '..') if len(data) > 75 else data


Even shorter :

info = data[:75] + (data[75:] and '..')


Even more concise:

data = data[:75]

If it is less than 75 characters there will be no change.


matomo