Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Python Program for Text Wrapping

    Python Programming Examples


    This Python program demonstrates textwrap class functionality to format and wrap plain texts. It does the text formatting by adjusting the line breaks in the input paragraph, making the text well-formatted and beautiful.

    Example:

    #Importing the textwrap module
    import textwrap
    
    #Define a dummy text
    texts = """This method wraps the input paragraph such that each line is at most width characters long in the paragraph. If the input has some content, it returns a list of lines as output."""
    
    # Wrap the text.
    wrapper = textwrap.TextWrapper(width=40)
    word_list = wrapper.wrap(text = texts)
    
    # Print output
    for element in word_list:
            print(element)
    

    Program Output:

    This method wraps the input paragraph
    such that each line is at most width
    characters long in the paragraph. If the
    input has some content, it returns a list
    of lines as output.


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.