Python Basics
Python Basics
Python Basics
The 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 in the terminal.
Every running program has a text output area called "standard out", or
sometimes just "stdout". The Python print() function takes in python data such
as ints and strings, and prints those values to standard out.
Let us start by writing and running our first code.
Delete the main.py file by clicking on the file and pressing the DELETE key.
Create a new file by right clicking on folder name -> New -> Python File.
Type in whatever name you want to give your file as per your preference and
press Enter.
When you check the output, you can see we can print anything we want in
terminal using the print statement. Also, we can do calculations using Python.
To run the program, right click on file and click run. In my case, file name is
hello.py, it would be same as the name you have given while creating the file.
Output:
Now let us use the END parameter and check the output.
Example 1:
print("Hello World", end="")
print("This is another print statement")
Output:
Example 2:
print("Hello World", end="joker")
print("This is another print statement")
print("This is a good language", end=" ")
print("Goodbye")
Output:
Escape Sequences
The programmers refer to the "backslash (\)" character as an escape character.
In other words, it has a special meaning when we use it inside the strings. As
the name suggests, the escape character escapes the characters in a string for
a moment to introduce unique inclusion.
• An Escape Sequence character in Python is a sequence of characters that
represents a single character.
• It does not 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 examples:
Example 1
print("Hello this is python.\nIt is a good language")
Output
Example 2
print("Hello this is python.\tIt is a good language")
Output
Comments
Programming reflects your way of thinking in order to describe the single steps
that you took to solve a problem using a computer. Commenting your code
helps explain your thought process, and helps you and others to understand
later the intention of your code. This allows you to find errors more easily, to
fix them, to improve the code later on, and to reuse it in other applications as
well.
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 describe what is happening inside a program so that a person
looking at the source code does not have difficulty figuring it out.
There are two types of comments in Python Language:
• Single line comment
• Multi line comment
Output
Output