Learn Python - 7 [Comments]

in #python7 years ago

Photo 28.03.2018 11 58 01 PM.jpg
Comments are lines of codes that don't execute. Generally, they are written by the author of the code. We need comments because we can't express ourselves all the time. But make sure that you don't write bad comments for example if a line of code does multiplication 3 * 5 it's obvious and its bad practice to write a comment for this line.
Always try to write code that explains itself so you wouldn't need to write comments. Of course, there will be comments all the time, even for you as the author of the code. Sometimes you will have hard times to understand what a part of the code does. Then comments will help you to understand it quickly.

Enough to say, now let's see how to write comments in python:

>>> # this is comment line
...
>>>

Anything starts with # is ignored by python.

>>> # x = 8 ** 2
... # y = 6 ** 2
... x = 55
>>> x
55
>>> y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'y' is not defined

If you want multiple comment line then put # in front of every line you want. As you see we defined y in the comment so when we try to get value y it gives an error because comments don't execute.

The most important thing about comments is to write them when it's hard to understand the code or if you can't express the code more then you did. Use meaningful names for variables.

Sort:  

Congratulations @mtndmr! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @mtndmr! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.24
TRX 0.25
JST 0.040
BTC 94242.56
ETH 3408.52
USDT 1.00
SBD 3.35