From Predictive Chemistry
Jump to: navigation, search

Abstracting = the process of turning a specific answer (or program) into a more general one. The code below uses x and y as abstract place-holders for the actual numbers of apples in the computation.

 # 4 apples - 1 apples gives me 3 apples left
 left = 4 - 1 # original, specific answer
 x = 4
 y = 1
 left = x - y # general, abstract answer

Argument = the Python objects sent as inputs to a function This example calls map with arguments abs and [-1,2,-3,4]

 map(abs, [-1,2,-3,4])

Code block = a group of Python code with the same number of spaces in front of the line. Here's an example of a block of 3 lines executed when x is larger than 4:

 if x > 4:
     x = x - 4
     z = z + "a"
     print x

Control flow = the order in which lines of code are executed by the Python interpreter. If-statements interrupt control flow by skipping over one of the branches. The third step could print either "Win" or "Lose".

 x = 100 # first step
 if x == 100: # second step
   print "Win" # true-branch
   print "Lose" # false-branch
 print "Game Over." # fourth step

Interpreter = the computer program that runs Python code. All Python code is run by the interpreter, usually by typing (at the $-prompt).

 $ python
 # You can also start an interactive interpreter
 $ python
 >>> # this prompt means you are now talking to Python
 >>> print "Hello World!"

List = a collection of Python objects inside brackets, []


Tuple = a collection of Python objects inside parentheses, ()

 ("string", 5*6, ['a'])

Type ... Every Python object has a type (like int, string, or float) that describes what kind of object it is.

 ~> <type 'int'>

Variable = a name used to refer to any Python object Note: Every word in your program other than special keywords (or words beginning with numbers) is treated as a variable.

x, y, hallo