λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

University of California, Berkeley/ElectricalEngineering & ComputerSciences

Interfaces

Interfaces

Describe how you can interact with an object without necessarily implementing it

Magic Methods

These are specially named methods that are callable outside the ordinary dot notation.

Example: __init__

str & repr

str

__str__ specifies what occurs when str is called on it

Used when calling print on an object

repr

__repr__ specifies what occurs when repr is called on it

Used when displaying an object in the interpreter

Enhancing Linked Lists

repr for Linked Lists

>>> lnk = Link(1, Link(2, Link.empty))

>>> lnk

Link(1, Link(2))

str for Linked Lists

>>> lnk = Link(1, Link(2, Link.empty))

>>> print(lnk)

<1, 2>

equality

Sequences

x in s , x not in s : Returns boolean representing membership

s + t : Concatenates two sequences

s * n, n * s : Concatenates n shallow copies

len(s) : Number of elements in sequence

s[i] : i’th item of sequence

s[i:j], s[i:j:k] : Slicing

membership : x is s, x not in s

concatenation : s + t

repetition : s * n, n * s

length : len(s)

indexing : s[i]

slicing : s[i:j], s[i:j:k]

'University of California, Berkeley > ElectricalEngineering & ComputerSciences' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

Scheme  (0) 2019.07.30
Week 6  (0) 2019.07.30
Linked Lists & Mutable Trees  (0) 2019.07.26
Inheritance  (0) 2019.07.24
Objects  (0) 2019.07.23