Statement, Indentation and Comment in Python

In this post we will discuss about Statement, Indentation and Comment in Python, how to use it write it and where to use it we will discuss everything here, What are the difference.

What is Statement in Python

A statement in Python is a single instruction that performs a specific task. Examples of statements in Python include assignments, function calls, conditional statements, loops, and more.

For example, the following line of code is a statement that assigns the value 5 to the variable x:

x = 5

What is Indentation in Python

Indentation refers to the whitespace at the beginning of a line of code that is used to group statements together. In Python, indentation is used to indicate the block of code that is executed together in a loop or conditional statement. The standard indentation in Python is four spaces.

For example, the following code demonstrates the use of indentation in a conditional statement:

x = 5
if x > 0:
    print("x is positive")
    print("x is negative")
x is positive

What is Comment in Python

Comments in Python are used to add explanations or notes to the code. Comments are ignored by the interpreter and are not executed. Comments can be added using the # symbol for single-line comments or using triple quotes (""") for multi-line comments.

For example, the following code demonstrates the use of comments:

# This is a single-line comment
x = 5 # This is an inline comment
This is a multi-line comment.
It can span multiple lines.

Here is Step by step video on how to install Python.

4 thoughts on “Statement, Indentation and Comment in Python”

Leave a Comment