COMPSCI 61A Lecture Notes - Lecture 17: Init, Message Passing, Return Ratio
zogo39484755 and 6 others unlocked
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents
Document Summary
Object value should behave like the kind of data it is meant to represent. For instance, by producing string representation of itself. Strings are important: they represent language and programs. In python, all objects produce two string representations: Str and repr strings are often the smae, but not always. Repr func returns a python expression (a string) that evaluates to an equal object. Returns canonical string representation of the obejct, for most object types, eval(repr(object)) == object. Result of calling repr on a value is what python prints in an interactive session. Some objects do not have a simple python readable string. Human interpretable strings are useful as well: Gives back value that is human interpretable representation of string. Result calling str on value of an expressino is what python prints using the print fucntino: Polymorphic function:function that applies to many )poly) different forms(morph) of data. Str and repr are both polymorphic; they apply to any object.