Python • Interpreter language: the Python interpreter executes each statement one at a time. • No compilation or linking is required. • Python programs are called scripts which are simple text files. To execute a script we pass it through the interpreter.
Data types • Basic data types – – Integer Float String Boolean (true or false) • Collections – – Lists Dictionaries (hash tables) Sets And more…
Expressions • • Numeric operators such as +, -, *, /, ** Logical operators such as and or String operators such as in, +, [], [: ] String and numeric functions such as len, abs, max, and min.
Assignment • name = value • Examples: – sequence = “ACCCATA” –x=5 –y=x+2
Lists • Ordered collection of basic types • Examples: – list 1 = [1, 2, 3] – list 2 = [4, 5] • Operations on lists – Concatenate: list 3 = list 1 + list 2 – Access nth element: list 1[n]
Dictionaries • Dictionaries are like arrays, except that they are indexed by user defined keys instead of non-negative integers. • Example – h={‘A’: ’T’, ‘C’: ’G’} • Operations on dictionaries – Lookup: h[key]
Input and Output • Input and output to files is done by creating a file object open(path, mode) • Example: f = open(“myfile. txt”, ”r”) f. readline()
Control structures • Conditional statements if expression : statements 1 else: statements 2 • Example max = 0 if(x > y): max = x else: max = y
Iteration • for count in range(start, stop, step): statements • for item in collection: do something with item