Software Engineers Handbook/Language Dictionary/Python

Python
Created by a Dutch programmer Guido Von Rossum, who had worked on ABC programming language, which itself derives from SETL programming language. ABC had indenting for syntax scoping and reading clarity, and SETL had list comprehensions and aimed for the clarity of set notation and theory.

Type
Python is described as a scripting language, and is usually run interpreted, although the interpreter scans the entire source for parsing prior to execution, and will halt if a syntax or type error occurs, presumably when constructing a parse tree that has nodes with type restrictions on their children.

Execution Entry Point
The entry point is a scripting if-conditional at the leftmost code containing indentation, using the global variable __name__, and the looking for the value "__main__"

General Syntax
Example of the assignment of 0 to a, then a to b:

Instead of the use of semi-colons to denote the end of statements in languages such as C++ and Java, python uses line breaks to denote the end of a statement. This means that each statement must be put on a separate line.

Comments
Block comments are specified by starting and ending with a set of triple quotation marks ("""). They can span multiple lines.

Variable Declarations
Variables are declared when first assigned. Python is dynamically typed, so the type of the variable depends on its initial value:

Function Declaration/Implementation
A function can be declared using the "def" keyword, then the function name. The arguments for the function are put in the parentheses. Code will only be part of a function if it is within the scope of that function.

You can create a function with an unknown number of arguments by using an asterisk:

Scope
Statements belong to the functional scope of the closest lower indent. There is a unnamed global functional scope. Variables and functions declared in any scope can't be accessed outside the scope they are declared in.

Conditional Statements
The "if" keyword denotes a conditional statement. If the condition is true, it will execute the code under the scope of the if statement. Otherwise, it will execute the code under the scope of the else statement. To check multiple conditions one after another, you can use the "elif" keyword (short for "else if"):

Looping Statements
For loops will loop through values between a given range: This range includes the starting value (0) but not the ending value (10), so it will go from i = 0 to i = 9.

You can also use a for loop to iterate through a list: While loops will loop until a condition becomes false. It will check the condition at the beginning of each loop.

Output Statements
Output in python is done using the built-in print function. The print function will automatically start a new line of output after printing. To print multiple items, separate them by a comma. Each item will automatically be printed with a space in between them.

Error Handling/Recovery


Containers
A list can be created like this: Python also has 3 more built-in containers: tuples, sets, and dictionaries. More types of containers can be added through external libraries.

Algorithms


Garbage collection
Garbage collection is automatic.

Physical Structure


Tips


Web References

 * Python Wikibooks

Books and Articles
