Python Tutorial 2---"Comments, Escape Sequences & Print Statement"

 Python Tutorial 2---

This PROGRAM or TUTORIAL about Python's  "Comments, Escape Sequences & Print Statement"

DOC

Comments in Python:

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.
  • The Interpreter does not execute comments.

There are two types of comments in Python Language -:

  • Single Line Comment
  • Multi-Line Comment

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

  • We use # (hash/pound to write single-line comments).

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 three quotes for writing multi-line comments). 

Python Print Statement:

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

end: end argument 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 string or even by space.

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 are shown below:


CODE

#TUT 2 - Comments, Escape Sequences & Print Statement
#Use hashtags for one-line comments
"""
use three
double quotes
for multiline comments
"""
print("Hello World", end=" ")
""" Use end="" for keep going in the same line.
You can put anything or nothing in the "".
You put something in the quotes it will show as it is
"""
print ("My name is Saswata")
print("Hello world, no other print command or end line command,")
print("c\saswata")
"""if you put c\harry & c\narry it will succesfully print harry but not narry because narry
thats because \n is an escape sequence.
BTW, "\" is called Backslash"""
#\t is tab. It will gives you a tab space if you put it in your print.
#There is many escape sequences we can Search GOOGLE for that
print("print statement") #this is a end print statement
"""
you can add a end print statement in the same line you used your print command
but you can't write a statement infront of your print command
because its hashtag or quote make the command into a statement/comment
but you can always use a statement/comment before by just using a separate line"""


OUTPUT


C:\Python38\python.exe C:/Users/Saswata/PycharmProjects/pythontuts/Tut2.py
Hello World My name is Saswata
Hello world, no other print command or end line command,
c\saswata
print statement

Process finished with exit code 0

Comments

Popular posts from this blog

Python Exercise 7 --- "Snake, Water, Gun"

Python Tutorial 38 --- "Self & __init__() (Constructors)(OOPS 3)"

Python Exercise 4 --- "Number Guessing Game"