How to make multiline comments, and autocompletion of quotes

Your explanation was awesome I have seen your comments in the previous section explaining about the strings that has been cleared my doubts tq

highlight the line and press cntrl + / so ur multi lines of code will be highlighted at once :wink:

9 Likes

when you enter the first double quote, place the cursor at the end of the double quote and put the double quote. “|” then “” |"

I thought triple quotes could only be used as doctrings…Then what is the difference between doctings and comments? Thanks!

Edited for added clarity-
There aren’t actually any multi-line comments in Python, using triple quotes just creates a string literal. Inside a function/class/module a string literal as the first statement is special and creates a docstring that is assigned as a special attribute. Otherwise it’s just treated as a string-

print("""test""")
Out: test

They are often used for handy multi-line comments (style guide permitting) as they have minimal effect on execution time. Using them as the first statement of functions etc. is just a special case (though arguably the best use).
True comments use ( # ).

8 Likes

Thanks for the help @stevencopeland

1 Like

You can write multi line comments inside triple quotes. It can be written as “”“triple double quotes”"" or ‘’‘triple single quotes’’’.

1 Like

:astonished:

Works with SQL as well! Thank you kind citizen :slight_smile:

Why one comment starts with # but multiline comment starts with “”" and end with “”" as well? Couldn’t that be simpler and more consistent?

# This is a comment

"""
This is not actually a comment
but is used like one
"""

Multiline comments don’t actually exist in Python. Rather, you’re actually creating a multiline string when you use """. For an explanation, here’s an old post on the forums: https://www.codecademy.com/forum_questions/505ba3cfc6addb000200e33c.

3 Likes

There is no multiline comment in Python. When you use “”", its taking up the memory (it is not the case when you use #), because it is considering as a multiline string and it has to store it.

1 Like

Hey @methodwhiz28097 you can use single triple quotes for multiline commenting like ‘’’ ‘’’

There’s indeed no multiline comment marker on the Python language, but the triple quotation markers can be used as a workaround. As noted in this article: there’s a need for attention while using the triple quotations while indenting.

  1. Comments in any form take up memory since the source code is in memory and comments are literally taking up space. They are still string literals.

  2. Python assigns any triple quoted string that immediately follows the signature line of a function to the built in docstring which can be queried with the help() function.

  3. String assignments include the triple quoted multiline string.

Just about everything we need to know about comments and multiline strings is in those three details.

2 Likes

once you type in triple quote it doubles it, so you have to clear(backspace) half of it by pressing the space button it will separate the quotes right where the cursor is, and then press the forward button to place your cursos on the next quote, then start clearing the extra quotes by pressing the backspace. repeat the process as much as u want.

What are some best practices for using multi-line comments in Python? How can you enable auto-completion of quotes in your code editor to improve your coding workflow?

By fulfilling the role one’s self:

'''

'''

Now just fill in the blank space between the two lines.

Aside

In Python, a comment looks like this:

# a comment

Multi-line comments are actually strings, namely, <class 'str'>

>>> type(''' ''')
<class 'str'>
>>> 

As such we can use them for preformatted text and assign them. The only thing that makes them comments is the omission of assignment.

Are there any particular code editors that are known for having exceptional auto-completion features for quotes and other characters?

TBH, I cannot say. I use a text editor for coding.

Since you use a text editor for coding, can you share any tips or tricks you use to enable auto-completion or improve your coding workflow in the absence of a built-in auto-complete feature?