3

My Visual Studio Code comment Python code with ''' instead of using # when I try to comment a block of code with the key combination Ctrl + Shift + a.

I'm using Ubuntu 16.04.

4
  • That’s the traditional way of “commenting out” multiple lines of text. Commented Sep 30, 2016 at 22:02
  • python interpret '''string''' as a string in python comment with # ¿There any way to comment code with visual studio with # python code? Commented Sep 30, 2016 at 22:09
  • I don’t use Visual Studio, so I have no idea. Commented Sep 30, 2016 at 22:13
  • 1
    And your question is...? Commented Sep 30, 2016 at 22:51

4 Answers 4

9

For VS Code and Python,

  • Select the block of code

  • To Comment press: Ctrl + k + u

  • To Uncomment press: Ctrl + k + u

Sign up to request clarification or add additional context in comments.

1 Comment

is there a way to change this setup (Ubuntu 20.04)?
6

Under Windows environment this work for me :

  • select block text
  • press CTRL + /

Comments

3

This has nothing specifically to to with Visual Studio, but a result of the python commenting styles. Generally, single line comments are done with the pound (or hash) symbol:

# This is a comment

In contrast, three quotation marks (either ''' or """) can be used to easily produce multi-line comments.

'''
This is also a comment.
However, this comment crosses multiple lines
'''

or

"""
This is yet another multiline comment
For long comments the quotation marks are much easier than # comments.
"""

Hope this helps.

1 Comment

Technically, that's a multi-line string literal, not a comment. But the Python byte code compiler recognizes literals that are not assigned anywhere and either ignores them sort of like comments (if they're in the middle of the code) or stores them as docstrings (if they're at the top of a module, class, function or method).
0

I found a solution at KINDA CODE.

  1. Select the block of code.
  2. Press Ctrl + K
  3. Press Ctrl + C

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.