Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For python we have adopted PEP

  • Overview

    • All functions, class methods, and variable names should be snake_cased

    • All class names should be CamelCased

    • Constants and global variables should be UPPER_CASED

    • Long function calls should use vertical alignment

      Code Block
      languagepy
      example2 = function(first_var, second_var,
                          third_Var, fourth_var)
    • Big objects and lists should be spaced on multiple lines

      Code Block
      languagepy
      new_list = [
          'one', 'two', 'three',
          'four', 'five', 'six'
      ]
      
      new_obj = {
          'key_1': 'value_1',
          'key_2': 'value_2',
      }
    • Maximum line length is 79 characters

    • Do not use wildcard imports

      Code Block
      languagepy
      # don't do this
      import * from your_package
      
      # do this instead
      import your_class from your_package
    • Single quotes around your strings or double quotes around your string mean the same thing. You can choose what one you like more, but stick to it so you can use the alternative you didn’t choose instead of backslashes.

    • Some general spacing guidelines are listed below

      Code Block
      languagepy
      # add space on either side of all operators
      x = y + z 
      # not 
      x=y+z
      
      # no whitespace for function calls
      my_funtion()
      # not 
      my_funtion ()
      my_funtion( )
      
      # when indexing or slicing the brackets should be directly next collection
      collection[‘index’]
      # not 
      collection [‘index’]
      collection[ ‘index’ ]
  • https://www.python.org/dev/peps/pep-0008/

...