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,
- How to Install Python Modules in VS Code
- 3 Python program to add two numbers
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- Python: How to get Current Directory
- Python - Convert float to String
- Tkinter - add x and y padding to label text
- Check if String Contains a Substring - Python
- Read JSON File in Python Program
- How to Convert String to DateTime in Python
- Sorting an array using Bubble Sort in Python Programming
- Python Hello World! Program with code example (snippet)
- How to delete a dir or folder using Python code
- Change label (text) color in tkinter
- Set width and height for the label in tkinter
- Check version of pip package installer for Python
- Reading JSON file in Python with Examples
- Indent Python code in Notepad++
- tkinter - Hello World! Program
- How to resolve Failed to create interpreter PyCharm Error
- Base64 Encoding Decoding in Python Programming
- How to pip install Python Modules in VSCode
- How to take user input from the console in a Python program
- Take input argument from command line in Python Programming
- Python Program To Calculate Simple Interest (SimpleInterest.py)
- Calculate discount amount python code
More Posts:
- How to integrate Salesforce CRM Sales and Service with Microsoft Teams - Teams
- Deploy SharePoint wsp solution package using PowerShell - SharePoint
- How to install maven in macOS using Terminal Command - MacOS
- How to destroy PHP session() - PHP
- Install Oh My Zsh on Ubuntu Docker complete steps - Ubuntu
- How to Skip or Ignore JUnit test cases in Java - Java
- macOS Ventura 13: The default interactive shell is now zsh - zsh
- Turn Off Auto-Brightness on iPhone running iOS 16 - iOS