Comments, Escape Sequences & Print Statement

Comments are used to write something which the programmer does not want to execute. Comments can be written to mark author name, date when the program is written, adding notes for your future self, etc.

  • Comments are used to make the code more understandable for the programmer.
  • Comments are not executed by the Interpreter.

There are 2 types of comments in Python Language -:

  • Single Line Comment
  • Multi-Line Comment

Single Line Comment: Single Line comments are the comments which are created in a single line only i.e. they occupy the space of a single line only.

  • We use # (hash/pound to write single line comment).
  • E.g. the below program depicts the usage of comments

import os
#This is a comment
print("Main code started")

#Now I will write my code here:
print(os.listdir())

 

Multi Line Comment : Multi Line comments are the comments which are created by using multiple lines i.e. they occupy more than one line in a program.

  • We use ''' ….. Comment …. ''' for writing multi-line comments in python (Use lines enclosed with tripe quotes for writing multi-line comments). An example of multi-line comment is shown below:
import os
'''This is a comment
Author: Harry
Date: 27 November 2020
Multi-line comment ends here
'''
print("Main code started")

#Now I will write my code here:
print(os.listdir())

Python Print Statement:

print() is a function in Python language that allows us to display whatever is written inside of it. In case an operation is supplied to print, the value of the expression after the evaluation is printed on the screen. for example

import os
import flask

# print statement for printing strings
print("Harry is a programmer")

# Print statement with a literal
print(1+87)

#This will print "Harry is a programmer" and 88 on the screen respectively!

end: end command allows us to put something at the end of the line after it is printed. In simple words it allows us to continue the line with " " or ',' or anything we put inside these quotes of the end.
It simply joins two different print statements using some kind of symbol or even by space. Example:

import os
import flask

# print statement for printing strings
print("Harry is a programmer", end="**")

# Print statement with a literal
print(1+87)

#This will print "Harry is a programmer**88" on the screen 

Escape Sequences :

  • An Escape Sequence character in Python is a sequence of characters that represents a single character.
  • It doesn’t represent itself when used inside string literal or character.
  • It is composed of two or more characters starting with backslash \ but acts as a single character. Example \n depicts a new line character

Some more examples of escape sequence characters is shown below:

Code file as described in the video

#Please dont remove this line
"""
This is a
Multiline Comment
"""
"""
This is a comment
"""
# print("Subscribe CodeWithHarry now","Bhai video bhi like kar dena")
# print("next line")
# print("C:\'narry")
print("Harry is \n good boy \t1") #comment after statement

Comments(3)

sushil2002 1 month, 2 weeks ago
harry sirg aap kamal ho sir. isse achha tutoriel maine kabhi nhi dekha, maine aaj hi join kiya hai aapka channel . aise hi sir bante rhe videos. god bless you sir
Vivek-Mishra 3 weeks, 4 days ago
Full Notes and Source Code: https://github.com/Optimized-World/Complete-Python-Tutorial-and-Notes
Vivek-Mishra 3 weeks, 4 days ago
Remaining Codes will be updated Soon. Thanks, Harry Bhai for Awesome Tutorials

Resources

  1. File - Download here
  2. File - Download here
  3. File - Download here
  4. File - Download here
  5. File - Download here

Course Announcements

Any Course related announcements will be posted here

Course Content