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 | 'Hello' s = |
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 | 'coin', 'string', 'myriad'] # A list literal suits = [ |
Let's see another example of Dictionary.
1 | 'I': 1.0, 'V': 5, 'X': 10} numerals = { |
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 | 1, 2], 3) s = ([ |
Mutation
1 | 10] a = [ |
1 | 10] == [10] [ |
Example: Lists
You should watch this video to finish some challenge problems.