Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've recently started learning python, I'm using Python 3.4. I'm trying to understand If-Else statement syntax

x=2
if x:
print(x)

But I'm always encountering this Error

IndentationError: expected an indented block

I searched internet about this error, people says that this happens becasue of mixing of tabs and spaces. But in my code as you see, I haven't mixed any space or tab. I haven't used them in the first place except with if statement.

share|improve this question

put on hold as off-topic by gnat, GlenH7, MichaelT, Dan Pichelman, MainMa 2 mins ago

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Quick suggestion for the future when you already mastered the syntax and all. Check out PyCharm as your IDE because it takes care of all the indentation and much more leaving you more focused on solving the problem rather than dealing with silly syntax problems. –  AvetisG 2 days ago
    
@AvetisG and what about 'Tkinter' is it better than PyCharm –  Atinesh 2 days ago
2  
That's a bit of a subjective question but I would say PyCharm has a few if not a lot more ways of accomplishing things that make your use of time more efficient. Check this out Python IDE comparison. –  AvetisG 2 days ago
    
why didn't you ask at Stack Overflow? meta.stackexchange.com/a/129632/165773 –  gnat 2 days ago
5  
I'm voting to close this question as off-topic because it is about an implementation issue. –  GlenH7 2 days ago

1 Answer 1

up vote 0 down vote accepted

Python syntax is sensitive to whitespace. In Python, a new code block must start with a deeper level of indentation. Your if statement should be written as below, with the print statement at one deeper level of indentation.

if x:
    print(x)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.