In this Python tutorial, we will discuss how to comment lines in python. Also, we will discuss:
- Comment single line in python
- Comment multiple lines python
Comment lines in Python
While programming in Python, we need to comment lines in Python.
Comment Single line python
In Python, the single-line comment starts with this ” # “ and it will ignore everything written with this. Comments are used to prevent the execution while testing code also comments are used to explain the code and it makes code more readable.
# Single line comment a = 'Hello World' print(a)
After writing the above code (comment Single line python). Here, you can see that before code I have used the ” # “ to comment that line. So in this way, comments work while working with code. You can refer to the below screenshot for comment Single line python.
Comment multiple lines python
To comment multiple lines in python we will use this ” # ” and we have to comment every line individually, which is very monotonous.
# This is multiline comment # Used for comment # Every line in this way a = 'Hello World' print(a)
After writing the above code (comment multiple lines in python). Here, you can see that before code I have used the ” # “ to comment every line so this is the way to comment multiline in python. So in this way, comments work while working with code. You can refer to the below screenshot for comment multiple line python.
You may like following Python tutorials:
- Python Hello World Program (using Pycharm)
- Python dictionary append with examples
- Check if a list is empty in Python
- Python convert list to string
- Python square a number
- What is a Python Dictionary + Create a dictionary in Python
- Python print without newline
- Python Dictionary Methods + Examples
- Python access modifiers + Examples
In this tutorial, we have seen how to comments lines in python. Also, we have discussed how to comment Single line and multiple comments in python.