This is the lecture note of CS61A - Lecture 13.
Objects
Object is an important concept in software engineering.
1 | # Object Examples |
String
Strings are objects, so they have attributes and methods. Let's see some examples.
1 | s = 'Hello' |
1 | a = 'A' |
1 | from unicodedata import name, lookup |
Mutation Operations
Only objects of mutable types can change their value over time.
- list
- dictionary
- set
Let's see an example of List.
1 | suits = ['coin', 'string', 'myriad'] # A list literal |
Let's see another example of Dictionary.
1 | numerals = {'I': 1.0, 'V': 5, 'X': 10} |
Tuples
Tuples are immutable sequences, meaning they are unchangable.
1 | (3, 4, 5, 6) |
However, an immutable sequence may still change if it contains a mutable value as an element.
1 | s = ([1, 2], 3) |
Mutation
1 | a = [10] |
1 | [10] == [10] |
Example: Lists
You should watch this video to finish some challenge problems.