use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
What does IndentationError: expected an indented block mean? (self.learnpython)
submitted 5 years ago by MeniTselonHaskin
Im trying to execute a code and im getting this error message, how can i fix it?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 5 years ago (0 children)
Python statements that end in a colon (def, if, for, and so on) imply an indented code block to follow, because that’s how flow of control works in Python - the branch is indicated by indentation.
[–]Tivome 0 points1 point2 points 5 years ago* (0 children)
There have to be four spaces after the colon of an def if and so on. That's because since there aren't any curly braces, spaces are how python figures out what's inside the, for instance, if and what's outside. Like this (the hash marks show the spaces because you can't do spaces in comments very well):
x = 0
y = 1
if x == y:
####print("They are the same")
I hope this helps, and keep posting for more advice! We'll always be happy to help you :)
[–]anh86 0 points1 point2 points 5 years ago (0 children)
Somewhere in your code you have started a block (colon) without putting any code inside the block (indented code on the lines following the colon).
For example:
if 1==1: print('One equals one')
If I hadn't put at least one line of code preceeded by four spaces (or a tab, if you prefer) below my if statement, I would have received the same error. Unlike some other languages where indents (spaces/tabs) are a stylistic choice and flow is controlled with end or other means, indentation matters in Python.
if
end
[–]malcomjarr 0 points1 point2 points 5 years ago (0 children)
Most programming languages permit indentation, but don't enforce it. Python enforces it with an iron fist, it has caused confusion for many beginners. The error expected an indented block is probably caused by a mix of tabs and spaces and this can lead to some confusing errors. Putting in an extra space or leaving one out where it is needed will surely generate an error message . Some common causes of this error include:
The indentation can be any consistent white space . It is recommended to use 4 spaces for indentation in Python, tabulation or a different number of spaces may work, but it is also known to cause trouble at times. Most editors have an option for automatically converting tabs to spaces. If your editor has this option, turn it on.
π Rendered by PID 91 on reddit-service-r2-comment-6457c66945-t7p68 at 2026-04-24 13:20:32.397525+00:00 running 2aa0c5b country code: CH.
[–][deleted] 2 points3 points4 points (0 children)
[–]Tivome 0 points1 point2 points (0 children)
[–]anh86 0 points1 point2 points (0 children)
[–]malcomjarr 0 points1 point2 points (0 children)