Comments & Escape Sequences In Python. Topic 5


Today’s topics about Comments & Escape Sequences In Python. Topic 5. It is one of the most important topics in Python.

print statement

In Python, the print statement is used to display output to the console. Here’s a basic example:

print("Hello, World!")

The Output Of This Code Will Be:

Hello, World!


We use comments in the codes for extra notes and explanations. And these comments are not executed. We can use comments using the hash symbol (#)

Comments are two types: i) Single line comments ii) Multi-line comments.

Let’s see some examples:

print("Python Programming") #this is comments 
# Also this line will be not executed by python

The Output Of This Code Will Be:

Python Programming

These two lines that we write after the hash(#) sign, this is a comment.  When the Python program executes, ignore this line. This is single-line comments. Now see what is multi-line comments:

When we write something between ”’ multi-line comment”’ that is called multi-line comments. We also can write it within “”” multi-line comment “””. We use multiple for commenting big amounts of code. Sometimes multi-line comments make more easier to maintain the code.A good programmer always uses comments in his code for future reference. For example:

#multi lines comments
print("Python Programming") 
print("I don't need a sorting algorithm; you've already ranked first in my heart.") 
print("In a world of zeros, you're my one and only.") 
print("Love is an infinite loop; fortunately, I enjoy getting stuck with you.")
print("You're the API to my heart, making every call asynchronous.")

The Output Of This Code Will Be:

You're the API to my heart, making every call asynchronous.

Escape Sequence:

In Python programming, we use an Escape sequence to include some special characters. We can’t include some special characters directly in our program.  With the help of the escape sequence, we can include these characters. Using ‘\’ backslash we can use special characters.

The most used escape sequence characters are:

– \n: New line

– \t: Tab

– \’: Single quote

– \”: Double quote

– \\: Backslash

print("This is a new line.\nSee, it starts from a new line.")
print("This is a tab.\tSee, it's indented.")
print("This is a double quote: \"")

The Output Of This Code Will Be:

This is a new line.
See, it starts from a new line.
This is a tab.  See, it's indented.     
This is a double quote: "

Escape sequences are used to control characters like newline (\n), tab (\t), or include special characters in a string.

I hope you understand Comments & Escape Sequences In Python. If you do not understand this topic just comment below with your email ID, and I will mail back to you.

Finite number of  lines code and infinite possibilities

Programmer, Arpan Bera

Leave a Reply

Your email address will not be published. Required fields are marked *

Arpan Bera

Coding is like Love – everyone can start, but only a few finish without errors

Keep Updated to our News and Blog