...

/

Quotes and Letter Case Related Tips

Quotes and Letter Case Related Tips

Learn how to document the code and how quotes can be used in Python.

Use quotes of all sorts

We can enclose string literals in Python in four types of quotation marks.

  • ' '
  • " "
  • ''' '''
  • """ """

Single and double quotation marks define single-line strings. Line breaks aren’t allowed within:

'Mary had a little lamb'
"Mary had a little lamb"

There’s no difference between single and double quotation marks in Python. This is unlike C, C++, and Java, where single marks are used for individual characters and double marks are used for strings, or PHP, where double-quoted strings are interpreted but single-quoted strings are not. Choosing single or double quotation marks is a matter of personal preference. Triple-single and triple-double quotation marks define multiline strings. They can include literal line breaks.

Press + to interact
print('''Mary had a little lamb''')
print("""Mary had a little lamb""")
# We can print in multiple lines using triple-quotes
print('''Mary had a
little lamb''')

Again, there’s no difference between triple-single and triple-double quotation marks. We can use whatever we like. but we have to try to be consistent.

Keep letter case consistent

Any Python identifier must start with a Latin letter (“a” through “z” or “A” through “Z”) or an underscore and contain only Latin ...