What to do with Unexpected indent in python

0 votes
How do I rectify the error "unexpected indent" in python?
Feb 8, 2022 in IoT (Internet of Things) by Nandini
• 5,480 points
831 views

1 answer to this question.

0 votes

Unexpected indent error occurs when there is some misalignment in the code. This could be due to whitespaces used in Python, as Python is a structured programming language and follows proper indentations.
For Example: using in a  for loop 

animals = ['cat','dog','rat']
for item in animals:
print(item)
IndentationError: expected an indented block

The correct way is:

animals = ['cat','dog','rat']
for item in animals:
    print(item)

Output

cat
dog
rat

Here, in the above example four whitespaces are required and if not followed correctly then there is an indented block error.
Thus, if proper spacing and correct whitespaces are not used there ae chances to get this error in python.
Hope this was helpful.

answered Feb 9, 2022 by Dev
• 6,000 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

What is the best way to retrofit existing alarm PIR with esp8266/etc?

Here is an explanation that best fits ...READ MORE

answered Sep 4, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,023 views
0 votes
1 answer

What is the Best practice to create automatic reports with Cumulocity?

There is a new feature regarding reporting ...READ MORE

answered Nov 23, 2018 in IoT (Internet of Things) by Shubham
• 13,490 points
852 views
0 votes
1 answer
0 votes
1 answer

Display time in a Windows Core IoT app with a clock!

It is possible, but you should understand ...READ MORE

answered Jul 10, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,557 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,441 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP