Tech

Some Quick Notes On Python Syntax…

Some Quick Notes On Python Syntax:

  • Python was designed for readability, and has some similarities to the English language with influence from mathematics.
  • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
  • Python relies on indentation (using whitespace), to define scope; such as the scope of loops, functions, & classes. Other programming languages often use curly-brackets for this purpose.
  • Python uses the colon symbol (:) and indentation for showing where blocks of code begin and end. That is, blocks in Python, such as functions, loops, ‘if’ clauses and other constructs, have no ending identifiers (other than the start of a new line with no indentation). All blocks start with a colon and then contain the indented line below it.
  • Use 4 spaces per indentation level!!!
    • Spaces (not tabs!) are the preferred indentation method. Tabs should only be used to remain consistent with code that is already indented with tabs. Python 3 disallows mixing the use of tabs & spaces for indentation. Python 2 code indented with a mix of both should be converted to using spaces exclusively.
    • In short: ALWAYS use 4 spaces for indentation!!!