Python Tutorial
What is Python ??
Python Get Started
Python Syntax
Python Variables and Types
Python Data Types
Python Operators
Python Input and Output
Python If ... Else
Python While Loops
Python For Loops
Python Strings
Python Functions
Python Lambda Function
Author Profile Altaf Shaikh
Altaf Shaikh

BE Engg | Python Dev | Content Writer | Founder of TeachMeBro | Blockchain Dev | Django

Python Syntax

January 8th 2020

Basic Syntax of python
Basic Syntax of python

Python Indentation

One of the distinctive features of Python is its use of indentation to highlight the blocks of code. Whitespace is used for indentation in Python. All statements with the same distance to the right belong to the same block of code. Most of the programming languages like C, C++, Java use braces { } to define a block of code. So indentations are very important in python.

for i in range(5):
    print(i)

This will print numbers from 0 to 4

Let's try in the console

So if you skip the indentation python will give you an IndentationError like this,

Python Variables

Let's see the small introduction on variables and how to declare them in python. We will learn more about them in further tutorials.

x = 65
y = "Hello, Learners"

So this is how we simply declare variables in python.

Comments

Comments can be used to make the code more readable. Comments are used for the purpose of in-code documentation. Comments start with a # symbol, python interpreter will ignore the statement starting will this symbol. 

#This is a Comment

So this is how we comment line in python. 

Multi Line Comments

To add multi-line comment in python add the comment inside the triple quotes.

'''
This is 
Multi-line
comment
'''

#or

"""
This is also a
Multi-line
comment
"""