January 2019
Beginner
318 pages
8h 23m
English
The fill() function works similarly to textwrap.wrap, except it returns the data joined into a single, newline-separated string. This function wraps the input in text and returns a single string containing the wrapped text.
The syntax for this function is:
textwrap.fill(text, width)
text: Text to wrap.
width: Maximum length allowed of a wrapped line. The default value is 70.
Now, we will see an example of fill(). Create a fill_example.py script and write the following content in it:
import textwrapsample_string = '''Python is an interpreted high-level programming language.'''w = textwrap.fill(text=sample_string, width=50)print(w)
Run the script and you will get the output as follows:
student@ubuntu:~/work$ python3 ...
Read now
Unlock full access