Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does ''' mean in Python?

Have been told that in Python

'''

is used to indicate the start of a multi-line string.
However I have also been taught that this code also allows for the documentation of functions and modules.

Googling, surprisingly, doesn’t give a clear answer on what ”’ definitively refers to.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So how should I remember, as a beginner, what this Python code refers to?
A multi-line string? An operator to assist documentation? Both? Something else?

>Solution :

Triple quotes ''' (and """) is a marker for a string literal just like quote characters ' and ", which you can see in Python’s grammar for String and Bytes literals.

Its only difference to regular quotes is that newlines and unescaped quote characters are allowed within a triple-quoted string literal, which makes triple quotes ideal for documentation in natural language where newlines and unescaped quote characters can appear often.

It is why as a convention triple quotes are used for docstrings, as suggested in PEP-257, although you can still use regular quotes for docstrings.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading