Basic Syntax in Python
Basic Syntax in Python
in Python
• The print statement
• Quotations
• New line
• Comments
The print statement
print("Hello, world!")
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?
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
Syntax Error
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:
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: