61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The...
Transcript of 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The...
![Page 1: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/1.jpg)
61A Lecture 3
![Page 2: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/2.jpg)
Announcements
![Page 3: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/3.jpg)
Print and None
(Demo)
![Page 4: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/4.jpg)
None Indicates that Nothing is Returned
4
![Page 5: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/5.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
4
![Page 6: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/6.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
4
![Page 7: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/7.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
![Page 8: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/8.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
>>> def does_not_return_square(x):... x * x
...
![Page 9: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/9.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
>>> def does_not_return_square(x):... x * x
... No return
![Page 10: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/10.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
>>> def does_not_return_square(x):... x * x
... >>> does_not_return_square(4)
No return
![Page 11: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/11.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
>>> def does_not_return_square(x):... x * x
... >>> does_not_return_square(4)
No return
None value is not displayed
![Page 12: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/12.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
>>> def does_not_return_square(x):... x * x
... >>> does_not_return_square(4)
>>> sixteen = does_not_return_square(4)
No return
None value is not displayed
![Page 13: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/13.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
>>> def does_not_return_square(x):... x * x
... >>> does_not_return_square(4)
>>> sixteen = does_not_return_square(4)The name sixteen is now bound to the value None
No return
None value is not displayed
![Page 14: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/14.jpg)
None Indicates that Nothing is Returned
The special value None represents nothing in Python
A function that does not explicitly return a value will return None
Careful: None is not displayed by the interpreter as the value of an expression
4
>>> def does_not_return_square(x):... x * x
... >>> does_not_return_square(4)
>>> sixteen = does_not_return_square(4)>>> sixteen + 4
Traceback (most recent call last): File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
The name sixteen is now bound to the value None
No return
None value is not displayed
![Page 15: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/15.jpg)
Pure Functions & Non-Pure Functions
Pure Functions just return values
Non-Pure Functions have side effects
5
![Page 16: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/16.jpg)
abs
Pure Functions & Non-Pure Functions
Pure Functions just return values
Non-Pure Functions have side effects
5
![Page 17: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/17.jpg)
abs
Pure Functions & Non-Pure Functions
-2Pure Functions just return values
Non-Pure Functions have side effects
5
![Page 18: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/18.jpg)
abs
Pure Functions & Non-Pure Functions
-22
Pure Functions just return values
Non-Pure Functions have side effects
5
![Page 19: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/19.jpg)
abs
Pure Functions & Non-Pure Functions
-22
Pure Functions just return values
Non-Pure Functions have side effects
Argument
5
![Page 20: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/20.jpg)
abs
Pure Functions & Non-Pure Functions
-22
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
![Page 21: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/21.jpg)
abs
Pure Functions & Non-Pure Functions
-22
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
![Page 22: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/22.jpg)
abs
Pure Functions & Non-Pure Functions
-22
2, 100 pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
![Page 23: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/23.jpg)
abs
Pure Functions & Non-Pure Functions
-22
2, 100 pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
2 Arguments
![Page 24: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/24.jpg)
abs
Pure Functions & Non-Pure Functions
-22
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
2 Arguments
![Page 25: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/25.jpg)
abs
Pure Functions & Non-Pure Functions
-22
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
2 Arguments
![Page 26: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/26.jpg)
abs
Pure Functions & Non-Pure Functions
-22
-2 print
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
2 Arguments
![Page 27: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/27.jpg)
abs
Pure Functions & Non-Pure Functions
-22
-2None
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
2 Arguments
![Page 28: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/28.jpg)
abs
Pure Functions & Non-Pure Functions
-22
-2None
Python displays the output “-2”
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
5
2 Arguments
![Page 29: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/29.jpg)
abs
Pure Functions & Non-Pure Functions
-22
-2None
Python displays the output “-2”
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
Returns None!
5
2 Arguments
![Page 30: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/30.jpg)
abs
Pure Functions & Non-Pure Functions
-22
-2None
Python displays the output “-2”
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
A side effect isn't a value; it's anything that happens as a consequence of
calling a function
Returns None!
5
2 Arguments
![Page 31: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/31.jpg)
abs
Pure Functions & Non-Pure Functions
-22
-2None
Python displays the output “-2”
2, 1001267650600228229401496703205376
pow
Pure Functions just return values
Non-Pure Functions have side effects
Argument
Return value
A side effect isn't a value; it's anything that happens as a consequence of
calling a function
Returns None!
5
2 Arguments
(Demo)
![Page 32: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/32.jpg)
Nested Expressions with Print
6
![Page 33: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/33.jpg)
Nested Expressions with Print
print(print(1), print(2))
6
![Page 34: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/34.jpg)
Nested Expressions with Print
print(print(1), print(2))
6
![Page 35: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/35.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)
6
![Page 36: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/36.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)print(1)
func print(...) 1
6
![Page 37: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/37.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(1)
func print(...) 1
6
![Page 38: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/38.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(1)
func print(...) 1
None
6
![Page 39: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/39.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(1)
func print(...) 1
Noneprint(2)
2
6
func print(...)
![Page 40: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/40.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(...):2None
display “2”
print(1)
func print(...) 1
Noneprint(2)
2
6
func print(...)
![Page 41: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/41.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(...):2None
display “2”
print(1)
func print(...) 1
Noneprint(2)
2
None
6
func print(...)
![Page 42: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/42.jpg)
Nested Expressions with Print
print(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(...):2None
display “2”
print(...):None, NoneNone
display “None None”
print(1)
func print(...) 1
Noneprint(2)
2
None
6
func print(...)
![Page 43: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/43.jpg)
Nested Expressions with Print
Noneprint(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(...):2None
display “2”
print(...):None, NoneNone
display “None None”
print(1)
func print(...) 1
Noneprint(2)
2
None
6
func print(...)
![Page 44: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/44.jpg)
Nested Expressions with Print
Noneprint(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(...):2None
display “2”
print(...):None, NoneNone
display “None None”
print(1)
func print(...) 1
Noneprint(2)
2
None
6
func print(...)
![Page 45: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/45.jpg)
Nested Expressions with Print
Noneprint(print(1), print(2))
func print(...)
print(...):1None
display “1”
print(...):2None
display “2”
print(...):None, NoneNone
display “None None”
print(1)
func print(...) 1
Noneprint(2)
2
None
6
Does not get displayed
func print(...)
![Page 46: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/46.jpg)
Multiple Environments
![Page 47: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/47.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
Calling/Applying:
What happens?
8
![Page 48: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/48.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
What happens?
8
![Page 49: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/49.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
What happens?
8
![Page 50: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/50.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
What happens?
Name
8
![Page 51: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/51.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
Formal parameter What happens?
Name
8
![Page 52: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/52.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
Formal parameter
Body
What happens?
Name
8
![Page 53: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/53.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
Formal parameter
Body (return statement)
What happens?
Name
8
![Page 54: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/54.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
What happens?
Name
8
![Page 55: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/55.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
What happens?
Name
8
![Page 56: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/56.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
What happens?
Name
8
![Page 57: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/57.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
What happens?
Name
8
![Page 58: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/58.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
What happens?
operator: square function: func square(x)
Name
8
![Page 59: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/59.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
What happens?
operator: square function: func square(x)
Name
8
![Page 60: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/60.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
What happens?
operator: square function: func square(x)
Name
8
![Page 61: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/61.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying:
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Name
8
![Page 62: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/62.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Name
8
![Page 63: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/63.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
Name
8
![Page 64: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/64.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
4
Name
8
![Page 65: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/65.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
4
16
Name
8
![Page 66: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/66.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
4
16Argument
Name
8
![Page 67: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/67.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
4
16Argument
Return value
Name
8
![Page 68: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/68.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
4
16
A new frame is created!
Argument
Return value
Name
8
![Page 69: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/69.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
4
16
A new frame is created!
Parameters bound to argumentsArgument
Return value
Name
8
![Page 70: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/70.jpg)
Life Cycle of a User-Defined Function
Def statement:
Call expression:
square( x ):
return mul(x, x)
>>> def
square(2+2)
Calling/Applying: square( x ):
Def statement
Formal parameter
Body
Return expression
(return statement)
A new function is created!
Name bound to that function in the current frame
operand: 2+2 argument: 4
Operator & operands evaluated
Function (value of operator) called on arguments (values of operands)
What happens?
operator: square function: func square(x)
Signature
4
16
A new frame is created!
Parameters bound to arguments
Body is executed in that new environment
Argument
Return value
Name
8
![Page 71: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/71.jpg)
Multiple Environments in One Diagram!
9Interactive Diagram
![Page 72: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/72.jpg)
Multiple Environments in One Diagram!
9Interactive Diagram
![Page 73: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/73.jpg)
Multiple Environments in One Diagram!
square(square(3))
9Interactive Diagram
![Page 74: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/74.jpg)
Multiple Environments in One Diagram!
square(square(3))
9Interactive Diagram
![Page 75: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/75.jpg)
Multiple Environments in One Diagram!
square(square(3))
func square(x)
9Interactive Diagram
![Page 76: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/76.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)func square(x)
9Interactive Diagram
![Page 77: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/77.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)func square(x)
9
func square(x)
Interactive Diagram
![Page 78: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/78.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)
3
func square(x)
9
func square(x)
Interactive Diagram
![Page 79: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/79.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)
3
func square(x)
9
func square(x)
Interactive Diagram
![Page 80: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/80.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)
3
func square(x)
10
func square(x)
Interactive Diagram
![Page 81: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/81.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)
3
func square(x)
10
func square(x)
Interactive Diagram
![Page 82: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/82.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)9
3
func square(x)
10
func square(x)
Interactive Diagram
![Page 83: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/83.jpg)
Multiple Environments in One Diagram!
square(square(3))
square(3)9
3
func square(x)
10
func square(x)
Interactive Diagram
![Page 84: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/84.jpg)
Multiple Environments in One Diagram!
11
square(square(3))
square(3)9
3
func square(x)
func square(x)
81
Interactive Diagram
![Page 85: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/85.jpg)
Multiple Environments in One Diagram!
An environment is a sequence of frames.
11
square(square(3))
square(3)9
3
func square(x)
func square(x)
81
Interactive Diagram
![Page 86: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/86.jpg)
Multiple Environments in One Diagram!
An environment is a sequence of frames.
• The global frame alone
• A local, then the global frame11
square(square(3))
square(3)9
3
func square(x)
func square(x)
81
Interactive Diagram
![Page 87: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/87.jpg)
Multiple Environments in One Diagram!
An environment is a sequence of frames.
1
• The global frame alone
• A local, then the global frame11
square(square(3))
square(3)9
3
func square(x)
func square(x)
81
Interactive Diagram
![Page 88: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/88.jpg)
Multiple Environments in One Diagram!
An environment is a sequence of frames.
1
2
1
• The global frame alone
• A local, then the global frame11
square(square(3))
square(3)9
3
func square(x)
func square(x)
81
Interactive Diagram
![Page 89: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/89.jpg)
Multiple Environments in One Diagram!
An environment is a sequence of frames.
1
2
1
2
1
• The global frame alone
• A local, then the global frame11
square(square(3))
square(3)9
3
func square(x)
func square(x)
81
Interactive Diagram
![Page 90: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/90.jpg)
Names Have No Meaning Without Environments
An environment is a sequence of frames.
• The global frame alone
• A local, then the global frame12
1
2
1
2
1
Interactive Diagram
![Page 91: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/91.jpg)
Names Have No Meaning Without Environments
An environment is a sequence of frames.
• The global frame alone
• A local, then the global frame12
Every expression is evaluated in the context of an environment.
1
2
1
2
1
Interactive Diagram
![Page 92: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/92.jpg)
Names Have No Meaning Without Environments
An environment is a sequence of frames.
• The global frame alone
• A local, then the global frame12
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
1
2
1
2
1
Interactive Diagram
![Page 93: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/93.jpg)
Names Have No Meaning Without Environments
An environment is a sequence of frames.
• The global frame alone
• A local, then the global frame12
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
2
1
Interactive Diagram
![Page 94: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/94.jpg)
Names Have No Meaning Without Environments
An environment is a sequence of frames.
• The global frame alone
• A local, then the global frame12
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
2
1
Interactive Diagram
![Page 95: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/95.jpg)
Names Have No Meaning Without Environments
An environment is a sequence of frames.
• The global frame alone
• A local, then the global frame12
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
2
1
Interactive Diagram
![Page 96: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/96.jpg)
Names Have Different Meanings in Different Environments
13Interactive Diagram
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
![Page 97: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/97.jpg)
Names Have Different Meanings in Different Environments
13
A call expression and the body of the function being called are evaluated in different environments
Interactive Diagram
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
![Page 98: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/98.jpg)
Names Have Different Meanings in Different Environments
13
A call expression and the body of the function being called are evaluated in different environments
Interactive Diagram
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
![Page 99: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/99.jpg)
Names Have Different Meanings in Different Environments
13
A call expression and the body of the function being called are evaluated in different environments
Interactive Diagram
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
![Page 100: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/100.jpg)
Names Have Different Meanings in Different Environments
13
1
A call expression and the body of the function being called are evaluated in different environments
Interactive Diagram
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
![Page 101: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/101.jpg)
Names Have Different Meanings in Different Environments
13
1
2
1
A call expression and the body of the function being called are evaluated in different environments
Interactive Diagram
Every expression is evaluated in the context of an environment.
A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.
![Page 102: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/102.jpg)
Miscellaneous Python Features
Division Multiple Return Values
Source Files Doctests
Default Arguments
(Demo)
![Page 103: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/103.jpg)
Conditional Statements
![Page 104: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/104.jpg)
Statements
16
A statement is executed by the interpreter to perform an action
![Page 105: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/105.jpg)
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Compound statements:
Statements
16
A statement is executed by the interpreter to perform an action
![Page 106: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/106.jpg)
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Compound statements:
Statements
Statement
16
A statement is executed by the interpreter to perform an action
![Page 107: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/107.jpg)
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Compound statements:
Statements
StatementClause
16
A statement is executed by the interpreter to perform an action
![Page 108: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/108.jpg)
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Compound statements:
Statements
Statement
Suite
Clause
16
A statement is executed by the interpreter to perform an action
![Page 109: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/109.jpg)
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Compound statements:
Statements
Statement
Suite
ClauseThe first header determines a statement’s type
16
A statement is executed by the interpreter to perform an action
![Page 110: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/110.jpg)
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Compound statements:
Statements
Statement
Suite
ClauseThe first header determines a statement’s type
The header of a clause “controls” the suite that follows
16
A statement is executed by the interpreter to perform an action
![Page 111: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/111.jpg)
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Compound statements:
Statements
Statement
Suite
ClauseThe first header determines a statement’s type
The header of a clause “controls” the suite that follows
def statements are compound statements
16
A statement is executed by the interpreter to perform an action
![Page 112: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/112.jpg)
Compound Statements
Compound statements:
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Suite
17
![Page 113: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/113.jpg)
Compound Statements
Compound statements:
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Suite
A suite is a sequence of statements
17
![Page 114: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/114.jpg)
Compound Statements
Compound statements:
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Suite
A suite is a sequence of statements
To “execute” a suite means to execute its sequence of statements, in order
17
![Page 115: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/115.jpg)
Compound Statements
Compound statements:
<header>: <statement> <statement> ... <separating header>: <statement> <statement> ... ...
Execution Rule for a sequence of statements:
• Execute the first statement
• Unless directed otherwise, execute the rest
Suite
A suite is a sequence of statements
To “execute” a suite means to execute its sequence of statements, in order
17
![Page 116: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/116.jpg)
Conditional Statements
18
(Demo)
![Page 117: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/117.jpg)
Conditional Statements
18
(Demo)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
![Page 118: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/118.jpg)
Conditional Statements
1 statement, 3 clauses,3 headers, 3 suites
18
(Demo)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
![Page 119: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/119.jpg)
Conditional Statements
1 statement, 3 clauses,3 headers, 3 suites
18
(Demo)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Execution Rule for Conditional Statements:
![Page 120: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/120.jpg)
Conditional Statements
1 statement, 3 clauses,3 headers, 3 suites
Each clause is considered in order.
1. Evaluate the header's expression.
2. If it is a true value, execute the suite & skip the remaining clauses.
18
(Demo)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Execution Rule for Conditional Statements:
![Page 121: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/121.jpg)
Conditional Statements
1 statement, 3 clauses,3 headers, 3 suites
Each clause is considered in order.
1. Evaluate the header's expression.
2. If it is a true value, execute the suite & skip the remaining clauses.
18
Syntax Tips:
(Demo)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Execution Rule for Conditional Statements:
![Page 122: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/122.jpg)
Conditional Statements
1 statement, 3 clauses,3 headers, 3 suites
Each clause is considered in order.
1. Evaluate the header's expression.
2. If it is a true value, execute the suite & skip the remaining clauses.
18
Syntax Tips:
1. Always starts with "if" clause.
2. Zero or more "elif" clauses.
3. Zero or one "else" clause,always at the end.
(Demo)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Execution Rule for Conditional Statements:
![Page 123: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/123.jpg)
Boolean Contexts
19
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
George Boole
![Page 124: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/124.jpg)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Boolean Contexts
George Boole
20
![Page 125: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/125.jpg)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Boolean Contexts
George Boole
20
Two boolean contextsTwo boolean contexts
![Page 126: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/126.jpg)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Boolean Contexts
False values in Python: False, 0, '', None
George Boole
20
Two boolean contextsTwo boolean contexts
![Page 127: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/127.jpg)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Boolean Contexts
False values in Python: False, 0, '', None (more to come)
George Boole
20
Two boolean contextsTwo boolean contexts
![Page 128: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/128.jpg)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Boolean Contexts
False values in Python: False, 0, '', None
True values in Python: Anything else (True)
(more to come)
George Boole
20
Two boolean contextsTwo boolean contexts
![Page 129: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/129.jpg)
def absolute_value(x): """Return the absolute value of x.""" if x < 0: return -x elif x == 0: return 0 else: return x
Boolean Contexts
False values in Python: False, 0, '', None
True values in Python: Anything else (True)
(more to come)
George Boole
Read Section 1.5.4!
20
Two boolean contextsTwo boolean contexts
Reading: http://composingprograms.com/pages/15-control.html#conditional-statements
![Page 130: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/130.jpg)
Iteration
![Page 131: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/131.jpg)
While Statements
22
(Demo)
![Page 132: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/132.jpg)
While Statements
22
(Demo)
![Page 133: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/133.jpg)
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
22
(Demo)
Execution Rule for While Statements:
![Page 134: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/134.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
22
(Demo)
Execution Rule for While Statements:
![Page 135: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/135.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
22
(Demo)
Execution Rule for While Statements:
![Page 136: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/136.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
22
(Demo)
Execution Rule for While Statements:
![Page 137: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/137.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
22
(Demo)
Execution Rule for While Statements:
![Page 138: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/138.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
22
(Demo)
Execution Rule for While Statements:
![Page 139: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/139.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
22
(Demo)
Execution Rule for While Statements:
![Page 140: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/140.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1
22
(Demo)
Execution Rule for While Statements:
![Page 141: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/141.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1
22
(Demo)
Execution Rule for While Statements:
![Page 142: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/142.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
11
22
(Demo)
Execution Rule for While Statements:
![Page 143: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/143.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
11
22
(Demo)
Execution Rule for While Statements:
![Page 144: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/144.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
11
22
(Demo)
Execution Rule for While Statements:
![Page 145: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/145.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 21
22
(Demo)
Execution Rule for While Statements:
![Page 146: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/146.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 21
22
(Demo)
Execution Rule for While Statements:
![Page 147: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/147.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 21 3
22
(Demo)
Execution Rule for While Statements:
![Page 148: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/148.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 21 3
22
(Demo)
Execution Rule for While Statements:
![Page 149: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/149.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 21 3
22
(Demo)
Execution Rule for While Statements:
![Page 150: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/150.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 2 31 3
22
(Demo)
Execution Rule for While Statements:
![Page 151: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/151.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 2 31 3
22
(Demo)
Execution Rule for While Statements:
![Page 152: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/152.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 2 31 3 6
22
(Demo)
Execution Rule for While Statements:
![Page 153: 61A Lecture 3 - University of California, BerkeleyNone Indicates that Nothing is Returned The special value None represents nothing in PythonA function that does not explicitly return](https://reader036.fdocuments.in/reader036/viewer/2022071007/5fc43f9bdea31473b11c0cd7/html5/thumbnails/153.jpg)
George Boole
While Statements
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1.
1 2 31 3 6
22
(Demo)
Execution Rule for While Statements: