There are two ways to write comments (docstring) in Python...
- # Single line comments - prpend any line with hash to write a comment
- """ Multiple line comments - add three tipple quotes to start and """ three tripple quotes to end the comment
To write single line comments in Python use literal '#'.
#Multiply two numbers
4*5
There is no space required between # and your comment but for clarity it is good to have space after #.
# Multiply two numbers
4*5
Comments don't require indentation in Python
def mult(a,b):
# Multiply two numbers
return(a*b)
mult(4,6)
One way to comment out multiple lines in Python is to add '#' in front of every line as shown below.
#Example below function takes two arguments and
#Returns the result
def mult(a,b):
return(a*b)
print(mult(5,4))
More preferred is to use tripple quotes before and after the comment as shown below.
"""
Example below function takes two arguments and
Returns the result
"""
def mult(a,b):
return(a*b)
print(mult(5,4))
Note - we can also use above method for single line comments.
""" Example below function takes two arguments and Returns the result """
def mult(a,b):
return(a*b)
print(mult(5,4))
Related Notebooks
- How To Take String Input From Command Line In Python
- How To Take Integer Input From Command Line In Python
- Strftime and Strptime In Python
- String And Literal In Python 3
- Summarising Aggregating and Grouping data in Python Pandas
- Merge and Join DataFrames with Pandas in Python
- How To Add Regression Line On Ggplot
- How To Code RNN and LSTM Neural Networks in Python
- Python Iterators And Generators