Statement, Indentation And Comment in Python


In programming statements are set of instructions. They are often goal or task oriented. For example, x=10 is a statement. In python programming there are many types of statement such as assignment(x-5), conditional and loop statement such as for, while and do while. There can be multi-line statements in python programming. They can be declared as using backslash at the end of each line.

There are several other ways to write multi-line functions such as

  • Parentheses

  • Square bracket

  • Semicolons


Indentation is a vital concept in python as compared to other languages. This is because in python language indentation of a block (i.e., set of statements) defines its scope. Other languages use braces to declare or define the scope of a block. So, in python language each line of block should start at the same level. Whitespace is used for indentation in python. To ident a block in python we must use same whitespaces throughout the whole block. If a nested block needs to be used, then indent that further with more whitespaces. Indentation also improves code readability and provides a clean look, which are essential part of good programming practices. It also improves traceability of error. Let us understand indentation through an example

With Indentation
Without Indentation
Try it yourself with add function that adds two numbers and prints them!


Comments are written by developers so that the function performed could be understood easily later. For example, you multiplied two numbers in your code, so you write that here I multiplied some numbers for some other function I want to perform just to remind yourself when you open your code again. Comments are optional but an important part and good programming practice. How to write comments in python. Any sentence followed by a “#” is comment. Comments do not affect program flow as they are ignored by compiler. Comments play an important part while maintenance and reuse of code. It also helps trace error in code. There are two types of comments.

Single line comments:

Single line comments are written followed by a # symbol without space. If it exceeds that line, insert # on the other line and so on

Single-line comment
Single-line comment
Multiple line comments

There can be some explanation of certain functions that exceeds more than 2,3 line. In python for multi-line comments just add “”” at start and end of comment. Let us check through example.

Multi-line Comment
(Visited 79 times, 1 visits today)

0 0 votes
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
gate io
16 days ago

I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me?

Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Would love your thoughts, please comment.x