
This action doesn’t actually comment out anything but only converts the code between the triple-quotes to a string. Command + / to comment and uncomment multiple lines of Python code on Mac.Īdvertisements If you don’t like the mentioned solution above, you can use the triple-quote trick to make a block of Python code not run.Ctrl + / (the slash key) to comment and uncomment lines of Python code on Windows.Command + K then Command + U if you’re on a Mac.Ctrl + K then Ctrl + U if you’re on Windows.They are just meant for the developers to understand a piece of code. It is used to increase the readability of a code. To uncomment a block of code, use your mouse to select it and then use the key combination: Comments in Python is just a short description along with the code. Command + K then press Command + C if you’re on a Mac.Some examples: this is the first comment. Ctrl + K then press Ctrl + C if you’re using Windows Since comments are to clarify code and are not interpreted by Python, they may be omitted when typing in examples.All you need to do is select that code block with your mouse, then press the following key combination: Comments that span multiple lines used to explain things in more detail are created by adding a delimiter () on each end of the comment.


For example: This would be a comment in Python. Advertisements Solutionįortunately, if you use Visual Studio Code, commenting out a block of code is really quick and easy. Single-line comments are created simply by beginning a line with the hash () character, and they are automatically terminated by the end of line. If a block of code had hundreds of lines, it would be terrible. To comment on a block of code in Python, you will have to prefix it with # line by line.
#PYTHON COMMENT HOW TO#
So how to comment out a block of code in Python? If you have worked with some other programming language like Javascript, Dart … then you will be familiar with / * * / syntax. To comment out a line of code in Python, you can add a # before that line.
