How Can I Define Multiline String In Python

Discussion in 'Programming' started by Gabriel9999, Apr 1, 2019.

  1. Gabriel9999

    Gabriel9999 New Member

    Joined:
    Mar 12, 2019
    Messages:
    23
    Likes Received:
    1
    Trophy Points:
    3
    How can I define multiline string Python and print to the screen? Thanks in advance for your help!
     
  2. samueltarcin9999

    samueltarcin9999 New Member

    Joined:
    Mar 12, 2019
    Messages:
    15
    Likes Received:
    11
    Trophy Points:
    3
    Well. You can use triple quotes in order to define multi line string like sss='''This is a string'''
    For more information look = poftut.com/python-string-variable-type/
     
    Gabriel9999 likes this.
  3. hussain mujtaba

    hussain mujtaba New Member

    Joined:
    Apr 15, 2020
    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    3
    Gender:
    Male
    You can use triple quotes to write multiline string or comments.Here is an example
    Code:
    string1=''' hello my name is
                           python3 '''
     
  4. JayAdams

    JayAdams New Member

    Joined:
    Dec 22, 2021
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Home Page:
    https://top10seosoftware.com/alternatives/webceo/
    In Python, you can define a multiline string using triple-quotes (''' or """). Here's an example:

    Code:
    multiline_string = '''
    This is a multiline string.
    It can span multiple lines.
    Use triple-quotes to define it.
    '''
    
    print(multiline_string)
    Or using double-quotes:


    Code:
    multiline_string = """
    This is another multiline string.
    It can also span multiple lines.
    Use triple-quotes with double-quotes to define it.
    """
    
    print(multiline_string)
    Both examples will output:

    Code:
    This is a multiline string.
    It can span multiple lines.
    Use triple-quotes to define it.
    
    This is another multiline string.
    It can also span multiple lines.
    Use triple-quotes with double-quotes to define it.
    Using triple-quotes allows you to include line breaks directly in the string, making it more readable and convenient for multiline text.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice