Multline string of python

I saw a interesting solution in Python pandas curriculum.

van_crimes_df = pd.read_sql('''SELECT TYPE, MONTH, DAY, NEIGHBOURHOOD
                            FROM van_crimes WHERE NEIGHBOURHOOD IN ("Stanley Park", "West End")''', conn)

Then, i replace the triple quote to single quote. And it is working also, but cannot be multiline.

van_crimes_df = pd.read_sql('SELECT TYPE, MONTH, DAY, NEIGHBOURHOOD FROM van_crimes WHERE NEIGHBOURHOOD IN ("Stanley Park", "West End")', conn)

So , i guess the ''' ''' not only used for commenting many lines of code, but in certain case, could return multiline “string” like a single-line string, and then as an string input to other function/method.

Is it common practice or any other use case?

Python convention is to use triple quotes as multi-line strings and docstrings. Multi-line comments should have # at the start of each line.

Python has also implicit string concatenation, which can sometimes be used to split long lines:

>>> 'abc' 'def'
'abcdef'
>>> ('abc'
 'def')
'abcdef'
>>> ('abc '
 'def')
'abc def'

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.