currently working on lab07
CS61A Week 6
- objects have attributes
today.year
and methodtoday.strftime(...)
- objects with good design will do what it supposed to do
str(tmr - today)
- objects contain built in informations
today.strftime(%A %B %d)
. We didn’t pass in any vocabulary in the constructor.
string is also object
Lists Are Mutable Objectes
- when assign an object to a name, name is just a alias..
- all the different names point to the same object
- the differences between
==
andis
- if a list is passed to a function through argument, the function can modify the list.
- even if it is not passed to the argument, function can still change the list
- a very dangerous and confusing desgin is the default value for argument
- When
append
,extend
,addition
,slicing
lists, it can be very confusing which generate new lists. Be careful!
Tuples Are Immutable Objects
- objects such as list and dict are mutable objects.
- tuple is similar to list, but it not mutable objects, it is not allowed to make new assignments to the tuple
- but it is not saying it’s impossible to change tuple
Iterator
or iterator for dict
Built-in functions for iteration: many built-in Python sequence operations return iterators that compute results lazily