How to write an inline-comment in Python How to write an inline-comment in Python python python

How to write an inline-comment in Python


No, there are no inline comments in Python.

From the documentation:

A comment starts with a hash character (#) that is not part of a string literal, and ends at the end of the physical line. A comment signifies the end of the logical line unless the implicit line joining rules are invoked. Comments are ignored by the syntax; they are not tokens.


Whitespace in Python is too important to allow any other kind of comment besides the # comment that goes to the end of the line. Take this code:

x = 1for i in range(10):             x = x + 1/* Print. */ print x

Because indentation determines scope, the parser has no good way of knowing the control flow. It can't reasonably eliminate the comment and then execute the code after it. (It also makes the code less readable for humans.) So no inline comments.


No, there are no inline-block comments in Python.But you can place your comment (inline) on the right.That's allows you to use syntax and comments on the same line.Anyway, making comments to the left of your code turn reading difficult, so...

Ex:

x = 1 # My variable