Python Programming Style Guide

 

Syntax Restrictions

Storage ClassesPython Style Guide

In order to help you become a more proficient programmer and problem solver, there are some components and basic syntax of the Python language that you are not allowed to use for this course.

Storage Structures

Multicomponent Data. You may not use a tuple, list, string, set, or dictionary to store records or multi-component data. You must use a storage class, unless explicitly stated otherwise.

Comparisons. Never use a non-string standard Python storage structure (tuple, list, set, dictionary, etc) as part of a logical expression. That is you should never compare two non-string storage structures

if myList == []:        # don't do this

if (a, b) == (0, 0):    # don't do this

Tuples. Tuples should only be used to

  • return multiple values from a function or method, and
  • to specify multiple arguments for formatted strings.

Slice Operation. You can not use the slice operation ([:] and [,]) for any reason unless explicitly stated otherwise.

String Formatting

You are not allowed to use the new style of string formatting introduced in Python version 3. You are to use the original C-style string formatting.

Class Definitions

A class definition should not include empty parentheses. For example, this is a correct definition

class MyClass:          # Do this

but the following is not

class MyClass():        # Don't do this
 

Instructions To Avoid

You may not use the following Python instructions in your programs unless explicitly indicated otherwise.

pass
continue

Miscellaneous

Checking Module Names

Do not use the following syntax within any of your modules.

if __name__ == "__main__":
  ........

In general, this syntax is meant for use within a non-driver module for testing purposes. But it can mess up the testing scripts used in grading your submissions. Thus, never use it for any modules in this course unless explicitly stated otherwise.



Storage ClassesPython Style Guide
Print -- Recent Changes
Page last modified on March 22, 2013, at 08:46 AM