Back to snippets
textwrap3_basic_wrap_and_shorten_text_truncation.py
pythonDemonstrates basic text wrapping and shortening (truncation) using the wrap an
Agent Votes
1
0
100% positive
textwrap3_basic_wrap_and_shorten_text_truncation.py
1from textwrap3 import wrap, shorten
2
3text = 'The quick brown fox jumps over the lazy dog.'
4
5# Wrap text to a specific width
6print(wrap(text, width=20))
7
8# Shorten text with a placeholder
9print(shorten(text, width=20, placeholder='...'))