61a lecture 12 - university of california, berkeleycs61a/fa18/assets/slides/... · 2019-01-11 ·...
TRANSCRIPT
![Page 1: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/1.jpg)
61A Lecture 12
![Page 2: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/2.jpg)
Announcements
![Page 3: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/3.jpg)
Objects
(Demo)
![Page 4: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/4.jpg)
Objects
4
![Page 5: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/5.jpg)
Objects
•Objects represent information
4
![Page 6: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/6.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
4
![Page 7: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/7.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
4
![Page 8: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/8.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
4
![Page 9: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/9.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
• Object-oriented programming:
4
![Page 10: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/10.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
• Object-oriented programming:
•A metaphor for organizing large programs
4
![Page 11: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/11.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
• Object-oriented programming:
•A metaphor for organizing large programs•Special syntax that can improve the composition of programs
4
![Page 12: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/12.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
• Object-oriented programming:
•A metaphor for organizing large programs•Special syntax that can improve the composition of programs
• In Python, every value is an object
4
![Page 13: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/13.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
• Object-oriented programming:
•A metaphor for organizing large programs•Special syntax that can improve the composition of programs
• In Python, every value is an object
• All objects have attributes
4
![Page 14: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/14.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
• Object-oriented programming:
•A metaphor for organizing large programs•Special syntax that can improve the composition of programs
• In Python, every value is an object
• All objects have attributes• A lot of data manipulation happens through object methods
4
![Page 15: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/15.jpg)
Objects
•Objects represent information
• They consist of data and behavior, bundled together to create abstractions
• Objects can represent things, but also properties, interactions, & processes
• A type of object is called a class; classes are first-class values in Python
• Object-oriented programming:
•A metaphor for organizing large programs•Special syntax that can improve the composition of programs
• In Python, every value is an object
• All objects have attributes• A lot of data manipulation happens through object methods• Functions do one thing; objects do many related things
4
![Page 16: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/16.jpg)
Example: Strings
(Demo)
![Page 17: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/17.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange
6
![Page 18: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/18.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
6
![Page 19: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/19.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
16 columns: 4 bits
6
![Page 20: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/20.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
16 columns: 4 bits
• Layout was chosen to support sorting by character code
6
![Page 21: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/21.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
16 columns: 4 bits
• Layout was chosen to support sorting by character code
• Rows indexed 2-5 are a useful 6-bit (64 element) subset
6
![Page 22: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/22.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
16 columns: 4 bits
• Layout was chosen to support sorting by character code
• Rows indexed 2-5 are a useful 6-bit (64 element) subset
• Control characters were designed for transmission
6
![Page 23: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/23.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
16 columns: 4 bits
• Layout was chosen to support sorting by character code
• Rows indexed 2-5 are a useful 6-bit (64 element) subset
• Control characters were designed for transmission
"Line feed" (\n)
6
![Page 24: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/24.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
16 columns: 4 bits
• Layout was chosen to support sorting by character code
• Rows indexed 2-5 are a useful 6-bit (64 element) subset
• Control characters were designed for transmission
"Line feed" (\n)"Bell" (\a)
6
![Page 25: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/25.jpg)
Representing Strings: the ASCII Standard
American Standard Code for Information Interchange8
rows
: 3
bits
16 columns: 4 bits
• Layout was chosen to support sorting by character code
• Rows indexed 2-5 are a useful 6-bit (64 element) subset
• Control characters were designed for transmission
"Line feed" (\n)"Bell" (\a)
6
(Demo)
![Page 26: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/26.jpg)
Representing Strings: the Unicode Standard
7
![Page 27: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/27.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
7
![Page 28: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/28.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters
7
![Page 29: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/29.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)
7
![Page 30: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/30.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
7
![Page 31: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/31.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order
7
![Page 32: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/32.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order•A canonical name for every character
7
![Page 33: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/33.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order•A canonical name for every character
U+0058 LATIN CAPITAL LETTER X
7
![Page 34: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/34.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order•A canonical name for every character
U+0058 LATIN CAPITAL LETTER X
U+263a WHITE SMILING FACE
7
![Page 35: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/35.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order•A canonical name for every character
U+0058 LATIN CAPITAL LETTER X
U+263a WHITE SMILING FACE
U+2639 WHITE FROWNING FACE
7
![Page 36: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/36.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order•A canonical name for every character
U+0058 LATIN CAPITAL LETTER X
U+263a WHITE SMILING FACE
U+2639 WHITE FROWNING FACE
'☺'7
![Page 37: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/37.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order•A canonical name for every character
U+0058 LATIN CAPITAL LETTER X
U+263a WHITE SMILING FACE
U+2639 WHITE FROWNING FACE
'☺' '☹'7
![Page 38: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/38.jpg)
Representing Strings: the Unicode Standard
http://ian-albert.com/unicode_chart/unichart-chinese.jpg
•109,000 characters•93 scripts (organized)•Enumeration of character properties, such as case
•Supports bidirectional display order•A canonical name for every character
U+0058 LATIN CAPITAL LETTER X
U+263a WHITE SMILING FACE
U+2639 WHITE FROWNING FACE
'☺' '☹'7
(Demo)
![Page 39: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/39.jpg)
Mutation Operations
![Page 40: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/40.jpg)
Some Objects Can Change
9
[Demo]
![Page 41: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/41.jpg)
Some Objects Can Change
First example in the course of an object changing state
9
[Demo]
![Page 42: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/42.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
![Page 43: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/43.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👶same_person
![Page 44: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/44.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👶BABY
same_person
![Page 45: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/45.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👶BABY
same_person
Unicode character
name
![Page 46: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/46.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👧GIRL
same_person
Unicode character
name
![Page 47: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/47.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👧GIRL
jessicasame_person
Unicode character
name
![Page 48: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/48.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👩WOMAN
jessicasame_person
Unicode character
name
![Page 49: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/49.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👵OLDERWOMAN
jessicasame_person
Unicode character
name
![Page 50: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/50.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👵OLDERWOMAN
jessicasame_person
Unicode character
name
All names that refer to the same object are affected by a mutation
![Page 51: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/51.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👵OLDERWOMAN
jessicasame_person
Unicode character
name
All names that refer to the same object are affected by a mutation
Only objects of mutable types can change: lists & dictionaries
![Page 52: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/52.jpg)
Some Objects Can Change
First example in the course of an object changing state
The same object can change in value throughout the course of computation
9
[Demo]
👵OLDERWOMAN
jessicasame_person
Unicode character
name
All names that refer to the same object are affected by a mutation
Only objects of mutable types can change: lists & dictionaries
{Demo}
![Page 53: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/53.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
![Page 54: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/54.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]
![Page 55: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/55.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4
![Page 56: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/56.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)
![Page 57: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/57.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
![Page 58: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/58.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
def mystery(s): s.pop() s.pop()
Interactive Diagram
![Page 59: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/59.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
def mystery(s): s.pop() s.pop()
Interactive Diagram
def mystery(s): s[2:] = []
or
![Page 60: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/60.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
>>> four = [1, 2, 3, 4]
def mystery(s): s.pop() s.pop()
Interactive Diagram
def mystery(s): s[2:] = []
or
![Page 61: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/61.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
>>> four = [1, 2, 3, 4]>>> len(four)4
def mystery(s): s.pop() s.pop()
Interactive Diagram
def mystery(s): s[2:] = []
or
![Page 62: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/62.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
>>> four = [1, 2, 3, 4]>>> len(four)4>>> another_mystery() # No arguments!
def mystery(s): s.pop() s.pop()
Interactive Diagram
def mystery(s): s[2:] = []
or
![Page 63: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/63.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
>>> four = [1, 2, 3, 4]>>> len(four)4>>> another_mystery() # No arguments!>>> len(four)2
def mystery(s): s.pop() s.pop()
Interactive Diagram
def mystery(s): s[2:] = []
or
![Page 64: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/64.jpg)
Mutation Can Happen Within a Function Call
A function can change the value of any object in its scope
10
>>> four = [1, 2, 3, 4]>>> len(four)4>>> mystery(four)>>> len(four)2
>>> four = [1, 2, 3, 4]>>> len(four)4>>> another_mystery() # No arguments!>>> len(four)2
def mystery(s): s.pop() s.pop()
def another_mystery(): four.pop() four.pop()
Interactive Diagram
def mystery(s): s[2:] = []
or
![Page 65: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/65.jpg)
Tuples
(Demo)
![Page 66: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/66.jpg)
Tuples are Immutable Sequences
12
![Page 67: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/67.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
![Page 68: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/68.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)
![Page 69: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/69.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()
![Page 70: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/70.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle
![Page 71: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/71.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
![Page 72: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/72.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]
![Page 73: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/73.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()
![Page 74: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/74.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle
![Page 75: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/75.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
![Page 76: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/76.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
Next lecture: ooze can change turtle's binding
![Page 77: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/77.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
Next lecture: ooze can change turtle's binding
![Page 78: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/78.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
Name change:
Next lecture: ooze can change turtle's binding
![Page 79: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/79.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change:
Next lecture: ooze can change turtle's binding
![Page 80: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/80.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change:
>>> x = 2
Next lecture: ooze can change turtle's binding
![Page 81: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/81.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change:
>>> x = 2
4
Next lecture: ooze can change turtle's binding
![Page 82: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/82.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change:
>>> x = 2
4>>> x = 3
Next lecture: ooze can change turtle's binding
![Page 83: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/83.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change:
>>> x = 2
4>>> x = 3
6
Next lecture: ooze can change turtle's binding
![Page 84: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/84.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
Next lecture: ooze can change turtle's binding
![Page 85: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/85.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 86: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/86.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 87: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/87.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 88: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/88.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 89: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/89.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 90: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/90.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 91: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/91.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> s = ([1, 2], 3)
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 92: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/92.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> s = ([1, 2], 3)>>> s[0] = 4
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 93: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/93.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> s = ([1, 2], 3)>>> s[0] = 4ERROR
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 94: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/94.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> s = ([1, 2], 3)>>> s[0] = 4ERROR
>>> s = ([1, 2], 3)
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 95: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/95.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> s = ([1, 2], 3)>>> s[0] = 4ERROR
>>> s = ([1, 2], 3)>>> s[0][0] = 4
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 96: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/96.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> s = ([1, 2], 3)>>> s[0] = 4ERROR
>>> s = ([1, 2], 3)>>> s[0][0] = 4>>> s
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 97: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/97.jpg)
Tuples are Immutable Sequences
Immutable values are protected from mutation
12
The value of an expression can change because of changes in names or objects
An immutable sequence may still change if it contains a mutable value as an element
>>> turtle = (1, 2, 3)>>> ooze()>>> turtle(1, 2, 3)
>>> turtle = [1, 2, 3]>>> ooze()>>> turtle['Anything could be inside!']
>>> x + x
>>> x + x
Name change: Object mutation:
>>> x = 2
4>>> x = 3
6
>>> x = [1, 2]
[1, 2, 1, 2]>>> x.append(3)
[1, 2, 3, 1, 2, 3]
>>> s = ([1, 2], 3)>>> s[0] = 4ERROR
>>> s = ([1, 2], 3)>>> s[0][0] = 4>>> s([4, 2], 3)
>>> x + x
>>> x + x
Next lecture: ooze can change turtle's binding
![Page 98: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/98.jpg)
Mutation
![Page 99: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/99.jpg)
Sameness and Change
14
![Page 100: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/100.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
14
![Page 101: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/101.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
14
![Page 102: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/102.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
14
![Page 103: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/103.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
14
![Page 104: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/104.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
![Page 105: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/105.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
>>> a = [10]
![Page 106: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/106.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
>>> a = [10]>>> b = a
![Page 107: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/107.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
>>> a = [10]>>> b = a>>> a == bTrue
![Page 108: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/108.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)
![Page 109: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/109.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue
![Page 110: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/110.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]
![Page 111: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/111.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
14
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 112: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/112.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 113: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/113.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 114: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/114.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> b = [10]
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 115: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/115.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> b = [10]>>> a == bTrue
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 116: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/116.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> b = [10]>>> a == bTrue>>> b.append(20)
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 117: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/117.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> b = [10]>>> a == bTrue>>> b.append(20)>>> a[10]
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 118: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/118.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> b = [10]>>> a == bTrue>>> b.append(20)>>> a[10]>>> b[10, 20]
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 119: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/119.jpg)
Sameness and Change
• As long as we never modify objects, a compound object is just the totality of its pieces
• A rational number is just its numerator and denominator
• This view is no longer valid in the presence of change
• A compound data object has an "identity" in addition to the pieces of which it is composed
• A list is still "the same" list even if we change its contents
• Conversely, we could have two lists that happen to have the same contents, but are different
14
>>> a = [10]>>> b = [10]>>> a == bTrue>>> b.append(20)>>> a[10]>>> b[10, 20]>>> a == bFalse
>>> a = [10]>>> b = a>>> a == bTrue>>> a.append(20)>>> a == bTrue>>> a[10, 20]>>> b[10, 20]
![Page 120: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/120.jpg)
Identity Operators
15
![Page 121: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/121.jpg)
Identity Operators
Identity
<exp0> is <exp1>
evaluates to True if both <exp0> and <exp1> evaluate to the same object
15
![Page 122: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/122.jpg)
Identity Operators
Identity
<exp0> is <exp1>
evaluates to True if both <exp0> and <exp1> evaluate to the same object
Equality
<exp0> == <exp1>
evaluates to True if both <exp0> and <exp1> evaluate to equal values
15
![Page 123: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/123.jpg)
Identity Operators
Identity
<exp0> is <exp1>
evaluates to True if both <exp0> and <exp1> evaluate to the same object
Equality
<exp0> == <exp1>
evaluates to True if both <exp0> and <exp1> evaluate to equal values
Identical objects are always equal values
15
![Page 124: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/124.jpg)
Identity Operators
Identity
<exp0> is <exp1>
evaluates to True if both <exp0> and <exp1> evaluate to the same object
Equality
<exp0> == <exp1>
evaluates to True if both <exp0> and <exp1> evaluate to equal values
Identical objects are always equal values
15
(Demo)
![Page 125: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/125.jpg)
Mutable Default Arguments are Dangerous
16
![Page 126: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/126.jpg)
Mutable Default Arguments are Dangerous
A default argument value is part of a function value, not generated by a call
16
![Page 127: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/127.jpg)
Mutable Default Arguments are Dangerous
A default argument value is part of a function value, not generated by a call
16
>>> def f(s=[]):... s.append(3)... return len(s)...
![Page 128: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/128.jpg)
Mutable Default Arguments are Dangerous
A default argument value is part of a function value, not generated by a call
16
>>> def f(s=[]):... s.append(3)... return len(s)... >>> f()1
![Page 129: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/129.jpg)
Mutable Default Arguments are Dangerous
A default argument value is part of a function value, not generated by a call
16
>>> def f(s=[]):... s.append(3)... return len(s)... >>> f()1>>> f()2
![Page 130: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/130.jpg)
Mutable Default Arguments are Dangerous
A default argument value is part of a function value, not generated by a call
16
>>> def f(s=[]):... s.append(3)... return len(s)... >>> f()1>>> f()2>>> f()3
![Page 131: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/131.jpg)
Mutable Default Arguments are Dangerous
A default argument value is part of a function value, not generated by a call
16Interactive Diagram
>>> def f(s=[]):... s.append(3)... return len(s)... >>> f()1>>> f()2>>> f()3
![Page 132: 61A Lecture 12 - University of California, Berkeleycs61a/fa18/assets/slides/... · 2019-01-11 · 61A Lecture 12. Announcements. Objects (Demo) Objects 4. Objects ... •A type of](https://reader034.vdocument.in/reader034/viewer/2022043003/5f844eecf3a9d4379447d43d/html5/thumbnails/132.jpg)
Mutable Default Arguments are Dangerous
A default argument value is part of a function value, not generated by a call
16Interactive Diagram
>>> def f(s=[]):... s.append(3)... return len(s)... >>> f()1>>> f()2>>> f()3
Each time the function is called, s is bound to the same value!