Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Introduction of Python
  5. Basic syntax in Python

Basic syntax in Python

Let’s write our first python program.

print("Hello, World!")

Indentation is one of the most important rules in python.

  • Use the colon (:) to start a block and press Enter.
  • All the lines in a block must use the same indentation, either space or a tab.
  • Python recommends four spaces as indentation to make the code more readable. Do not mix space and tab in the same block.
  • A block can have inner blocks with next level indentation.

Comments are also important in python. As it helps the code to be more understandable and readable.

We write comments in python using ‘#’.
There are two types of comments in python:-

  • Single line comment
  • Multiline comment
#single line comment
a=5
b=2
print(a+b)

#multiline comment
#addition of two numbers
#value of a and b is given
# we have to print the sum of two numbers
a=5
b=2
print(a+b)

This is the basic syntax of python.

Was this article helpful to you? Yes 1 No

How can we help?