All Courses

What is an indentation error

By Sde221876@gmail.com, 3 months ago
  • Bookmark
0

What is an indentation error

Python
Error
Indentation
2 Answers
0
Hitendradixit18@gmail.com

Check the spaces

0
Goutamp777

An indentation error occurs when there is a problem with the indentation of code blocks in a programming language. In many languages, indentation is used to define code blocks and determine the structure of a program. If the indentation is not done correctly, it can cause a syntax error.

For example, in Python, indentation is used to define the block of code that belongs to a loop, function, or class. If the indentation is not consistent or there is an extra indentation, it can cause an indentation error.

Here is an example of an indentation error in Python:

for i in range(10):
 print(i)
  print(i+1)

In this example, the second print statement is indented too far, which causes an indentation error. The correct way to write this code would be:

for i in range(10):
 print(i)
 print(i+1)

Indentation errors can be difficult to spot because they do not always cause a syntax error. If you are having trouble with an indentation error, it is usually a good idea to double-check the indentation of your code blocks and make sure that they are consistent.

Your Answer

Webinars

Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More