AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Python code blocks3/18/2024 However, Python indentation rules are quite simple, and most programmers already use indentation to make their code readable. Programmers familiar with other languages often bristle at the thought that indentation matters: Many programmers like the freedom to format their code how they please. For instance, the final print('All done!') is not indented, and so is not part of the else-block. But in Python, it is required for indicating what block of code a statement belongs to. In most other programming languages, indentation is used only to help make the code look pretty. The two blocks of code in our example if-statement are both indented four spaces, which is a typical amount of indentation for Python. To indicate a block of code in Python, you must indent each line of the block by the same amount. These ones happen to be only a single line long, but Python lets you write code blocks consisting of any number of statements. ') and print('Incorrect password.') are two separate code blocks. Consider the if-statement from our simple password-checking program: if pwd = 'apple': One of the most distinctive features of Python is its use of indentation to mark blocks of code. Learn More Buy Code Blocks and Indentation Python: Visual QuickStart Guide, 2nd Edition
0 Comments
Read More
Leave a Reply. |