Data
Every value has a type,
ex. type(1) = int
type(2.2) = float
type(1 + 1j) = complex
type(True / False ) = bool
True + True = 2
Properties of data types:
primitive expressions that evaluate to values of types
built-in functions, operators, methods manipulate values
int exact number
float finite approximation
complex
Objects
Objects represent information
Consist of data + behavior, bundled together create abstractions
Can represent things, numbers, processes, interactions
Type of object = Class
Class are first class values in Python
Object oriented programming:
metaphor for organizing large programs
special syntax that improve composition of programs
In Python, every value is an object
all objects have attributes
a lot of data manipulation through object methods
function do one thing, objects do many related things
Data Abstraction
Compound objects combine objects
A date: year, month, day
A geographic position: longitude , latitude
An abstract data type allows manipulation compound objects as units
Isolate any two parts of program that use data
How data represented (as parts)
How data manipulated (as units)
Data abstraction: methodology by which functions enforce abstraction barrier
between representation and use
Rational Numbers
numerator / denominator, both are integers
exact representation of fractions
( 1 / 3 ) not exact, finite approximation
Assume we can decompose & compose rational numbers
rational(n, d), return rational number X ---> Constructors
numer(x) return numerator x ---> Selectors
denom(x) return denominator x ---> Selectors Pairs as Tuples
A tuple literal: comma-separated expression
pair = (1, 2)
x, y = pair
x = 1, y =

More
Less