Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Learn Python Comments



In Python, comments are lines in the code that are not executed by the interpreter. They are used to explain the code, make it more readable, or prevent execution of code while testing. There are two types of comments in Python: single-line comments and multi-line comments.


1. Single-line Comments

Single-line comments start with the # symbol. Everything after the # on that line is ignored by the Python interpreter.

#This is a comment

Multiline Comments

Python does not have a specific syntax for multi-line comments like some other languages. However, you can use a series of single-line comments or use multi-line strings (triple quotes) that are not assigned to a variable.

Example 1: Using multiple single-line comments:

#This is a comment
#written in
#more than just one line

Example 2: Using multi-line strings:

""" This is a comment
written in
more than just one line """

As long as the string is not assigned to a variable, Python will read the code, but then ignore it, and you have made a multiline comment.



Advertisement





it pathshaala : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java