Python Fundamentals
How To Comment Python Code?
Comments are very important in computer programming . It describes what's going on inside a program so that a person looking at the source code does not have a hard time figuring it out. Comments in Python start with the hash character # and extend to the end of the physical line. Since comments are to clarify source code and are not interpreted by Python , they may be omitted when typing in examples.
#My first comment in Python
The above line is not executed in Python .
Another example:
# Adding 2 numbers
x = 10 # first variable
y = 20 # second variable
c = x + y # find the sum of variables
print(c)
output is 30
Python Multiline comments
If we have comments that extend multiple lines, one way of doing it is to use hash (#) in the beginning of each line.
# This is
# Multiple line
# Comments example
A common way to use comments for multiple lines is to use the triple-quoted strings(''') symbol.
'''
This is
multiple line
comment
'''
Note: Python does not support multiline comments like C/C++ or .Net . However there is nothing to stop you to use multi-line docstrings as multiline comments . This is also mentioned by Guido van Rossum, the creator of Python.
Related Topics
- Keywords in Python
- Python Operator - Types of Operators in Python
- Python Variables and Data Types
- Python Shallow and deep copy operations
- Python Datatype conversion
- Python Mathematical Function
- Basic String Operations in Python
- Python Substring examples
- How to check if Python string contains another string
- Check if multiple strings exist in another string : Python
- Memory Management in Python
- Python Identity Operators
- What is a None value in Python?
- How to Install a Package in Python using PIP
- How to update/upgrade a package using pip?
- How to Uninstall a Package in Python using PIP
- How to call a system command from Python
- How to use f-string in Python
- Python Decorators (With Simple Examples)
- Python Timestamp Examples