![]() Most programmers use two, four, or eight spaces. If you indent with spaces, you can actually use any number you like, so long as you’re consistent and unambiguous. Instead, you should add either a tab or a series of spaces at the start of the two lines that represent blocks: fname = "Gaurav " IndentationError: expected an indented block Tab size is automatically forced to 8 characters for all Python source files that contain some spaces in indentation. When you try to run the above code, you’ll get a message like this: File "tmp.py ", line 5 If fname = "Gaurav " and lname = "Siyal ": ![]() Here’s an example of incorrectly formatted Python code: fname = "Gaurav " ![]() This goes for functions, if clauses, and so on. ![]() The specifics of Python’s indentation rules are complex, but they boil down to one thing: indent code in blocks. The “IndentationError: expected an indented block” error is something you’re likely to see when you first start using Python, especially if you’ve come from another programming language. Why Do You Get the IndentationError in Python? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |