How to create a multiline string in the editor?

Is there any way to prevent the closing apostrophes from populating when opening the multi-line string?

3 Likes

I’m not sure why would you like to do that? It saves you time from writing them at the end.

The editor by default creates an empty doc_string,

''''''

The next thing to do is place the cursor in the middle and enter a newline (hard return).

'''
  Enter any block of multiline text (or hidden code)
  which will keep the formatting we give it.
'''

Note the term doc_string. That’s not exactly correct as this only applies when it is the first statement inside the function code block.

def foo(bar):
    '''
    a function to return the value of `bar`
    '''
    return bar

When we write this anywhere else in the source code it is strictly a comment unless assigned to a variable, in which case it becomes a multiline string, which also retains any formatting we give it.

We can access the doc_string by polling that attribute of the function.

>>> print (foo.__doc__)

    a function to return the value of `bar`
    
>>> 
4 Likes