You are on page 1of 18

Basic Syntax

in Python
• The print statement
• Quotations
• New line
• Comments
The print statement
print("Hello, world!")

When you want to display


text on the screen, you use The text must be surrounded
the print statement. by quotation marks inside
parentheses.
Main.py

print("Hello, world!")
print("I'm a Python program.")

Output
Hello, world!
I'm a Python program.
Main.py
print(2021)
print(50.2)

Output
2021
50.2
Commands learned
Command What does it do?

print(“text”) Prints entered text

print(number) Prints entered number


The use of quotations

Python accepts Single (‘), Double


(“) and Triple (”’ or “””) quotes to
denote the string literals.
The use of quotations

Program.py
Output
print("Hello, world!")
print("""Hello, world!""")
print('Hello, world!') Hello, world!
Hello, world!
print('''Hello, world!''') Hello, world!
Hello, world!
Python Convention
It is like python convention, that
single quotes are used for words,
double quotes for sentences and
triple quotes are mostly used to
span the string across multiple
lines.
Example on appropriate use
of Quotations

print('It's sunny cloudy day!')

Syntax Error

print(“It's sunny cloudy day!”)


Example on appropriate use
of Quotations
Triple Quote (""", ‘’’) - Allows strings to span multiple lines

Program.py
print("""
Today is Tuesday!
and it's cloudy day.
Output
""")
Today is Tuesday!
and it's cloudy day.
1. Using print() function, write a program describing yourself.

Sample Output:
1. Using print() function, write a
program to display the following
person.
Output:
New line(\n)
Prints the output in a new line or breaks
the statement inside the print function
Syntax:

print("Hello world. \n I have started learning Python.")

Output:
Hello world.
I have started learning Python.
Comments
• It is basically to help the coder about the flow of
a program. Python interpreter won’t interpret
the comment as a part of the program.
• Comment starts with a # sign.
Syntax:
# Hello world program
print("Hello world!")
Output:
Hello world!
1. Write three different ways to print the same
output as given below. Include comments in all
the method you used.
Sample Output:

You might also like