CS61A Lecture 10: Data Abstraction

3 Pages
Unlock Document

Computer Science
De Nero

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

Related notes for COMPSCI 61A

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.