- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Statement, Indentation and Comment in Python
In this tutorial, we are going to learn about the statement, indentation, and comments in Python. Let's see all of them one by one.
Statement
The instructions written in Python are called statements. Let's see the following program.
Example
print('Tutorialspoint') # statment
Output
If you run the above code, then you will get the following result.
Tutorialspoint
The one line that was written in the program is called statement. Every line in the program is a statement. Can't we write a multi-line statement? Why not, we can.
We can write the multi-line statements using the backslash (\).
Let's see how to write multi-line statements in Python.
Example
# multi-line statement result = 2 + 3 * \ 5 - 5 + 6 - \ 3 + 4 print(result)
Output
If you run the above code, then you will get the following result.
19
Indentation
Before talking about the indentation, let's see what is a block. A block is a set of statements instructions. Other programming languages like C, C++, Java, etc.., uses {} to define a block.But Python uses indentation to define a block.
So, how to write an indentation. There is nothing more than a tab. Each statement in the block must start at the same level.
Example
def find_me(): sample = 4 return sample find_me()
Output
If you run the above code, then you will get the following result.
4
Example
def find_me(): sample = 4 return sample find_me()
Output
If you run the above code, then you will get the following error as output.
File "<tokenize>", line 3 return sample ^ IndentationError: unindent does not match any outer indentation level
In the second program, the indentation level is not correct in the function block. So, we got an error. We must follow the indentation in Python. We can use the tab by default for indentation.
Comments
In Python, comments starts with hash (#) symbol. Let's see an example.
Example
# This is a comment # This too... a = 4 # a = 5 print(a)
Output
If you run the above code, then you will get the following result.
4
Unlike many other programming languages, there is no support for multi-line comments in Python. But, most of the people use docstrings as multi-line comments which is not a good practice.
Conclusion
If you have any doubts in the tutorial, mention them in the comment section.
- Related Articles
- Lines and Indentation in Python
- How to comment each condition in a multi-line if statement in Python?
- Why is indentation important in Python?
- Detection of ambiguous indentation in python
- Code indentation in Lua Programming
- Text Indentation using CSS
- Text Indentation Working with CSS
- How to add comment to column in MySQL using Python?
- Explain Try, Except and Else statement in Python.
- Sunlight and air are inexhaustible natural resources. Comment.
- The return Statement in Python
- How to write single line comment in Java?
- How to write multi-line comment in Java?
- How to add comment to chart in Excel?
- How to add hyperlink to comment in Excel?
