As all other programming languages, Python do supports multiple ways of adding comments to your code,
Comments in Python start with a # (hash) sign, all the lines in your code that start with # are ignored.
How to add a single line comment in Python
Example:#This is my python code comment line.
print("Welcome!")
How to place comment at the end of the line in Python?
Example:print("Pyhton comments!") #This comment will be ignored
How to comment out code in Python?
You can simply add a # (hash) at the start of each statement to comment it out.
Example:#print("I dont want this code")
print("I want this code")
How to add multi-line comment in Python?
Like Java we do not have a different syntax for muli-line comments in Python, one way is to add # at the start of each line.
Example:# This is
# a multiline
# comment in
# Python
print("Hello there!")
Another way of adding multiline comments is to enclose your comment with """ (3 double quotes - triple quotes)
Example:"""
This is
a multiline
comment in
Python
"""
print("Hello there!")
Comments:
- My Python comments were not working, realized i was using slash instead of hash :D, thank you!
user: anon 02 Oct 2020 11:01:11 GMT
- Python comments block is what I was looking for.
user: anon 02 Oct 2020 01:15:25 GMT
- How to convert python comments to markdown class documentation?
user: anon 01 Oct 2020 13:19:59 GMT
- " python comments are useful and recommended!
user: anon 28 Aug 2020 15:11:14 GMT
- /** is not Pyhton style of comments.
user: anon 27 Aug 2020 05:11:34 GMT
- Further comments disabled!
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
More Posts:
- Connect Azure AD (Active Directory) for PowerShell - Powershell
- How to get SharePoint Online user details from person or group column using REST API - SharePoint
- Enable Eclipse dark mode - Eclipse
- Java 20 (JDK) released and here is what is new and deprecated and deleted - Java
- Set Title to Android AlertDialog - Android
- Change label (text) color in tkinter - Python
- How to Change or Set a new Password for your Wi-Fi Router - HowTos
- JavaScript date in yyyy-MM-dd format - JavaScript