control announcements print and none
play

Control Announcements Print and None (Demo) None Indicates that - PowerPoint PPT Presentation

Control Announcements Print and None (Demo) None Indicates that Nothing is Returned 4 None Indicates that Nothing is Returned The special value None represents nothing in Python 4 None Indicates that Nothing is Returned The special value


  1. Life Cycle of a User-Defined Function What happens? Def statement: >>> def square( x ): return mul(x, x) Call expression: Calling/Applying: 8

  2. Life Cycle of a User-Defined Function What happens? Def statement: >>> def square( x ): return mul(x, x) Def statement Call expression: Calling/Applying: 8

  3. Life Cycle of a User-Defined Function What happens? Name Def statement: >>> def square( x ): return mul(x, x) Def statement Call expression: Calling/Applying: 8

  4. Life Cycle of a User-Defined Function What happens? Formal parameter Name Def statement: >>> def square( x ): return mul(x, x) Def statement Call expression: Calling/Applying: 8

  5. Life Cycle of a User-Defined Function What happens? Formal parameter Name Def statement: >>> def square( x ): return mul(x, x) Def statement Body Call expression: Calling/Applying: 8

  6. Life Cycle of a User-Defined Function What happens? Formal parameter Name Def statement: >>> def square( x ): return mul(x, x) Def statement Body (return statement) Call expression: Calling/Applying: 8

  7. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): return mul(x, x) Def statement Body (return statement) Call expression: Calling/Applying: 8

  8. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Def statement Body (return statement) Call expression: Calling/Applying: 8

  9. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) Call expression: Calling/Applying: 8

  10. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) Call expression: square(2+2) Calling/Applying: 8

  11. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) Call expression: square(2+2) operator: square function: func square(x) Calling/Applying: 8

  12. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Call expression: square(2+2) argument: 4 operator: square function: func square(x) Calling/Applying: 8

  13. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 operator: square function: func square(x) Calling/Applying: 8

  14. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) Calling/Applying: 8

  15. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) Calling/Applying: square( x ): 8

  16. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) Calling/Applying: square( x ): Signature 8

  17. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) 4 Calling/Applying: square( x ): Signature 8

  18. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) 4 Calling/Applying: square( x ): 16 Signature 8

  19. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) 4 Calling/Applying: square( x ): 16 Argument Signature 8

  20. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) 4 Calling/Applying: square( x ): 16 Argument Signature Return value 8

  21. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) A new frame is created! 4 Calling/Applying: square( x ): 16 Argument Signature Return value 8

  22. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) A new frame is created! 4 Calling/Applying: square( x ): Parameters bound to arguments 16 Argument Signature Return value 8

  23. Life Cycle of a User-Defined Function What happens? Formal parameter Return expression Name Def statement: >>> def square( x ): A new function is created! return mul(x, x) Name bound to that function Def in the current frame statement Body (return statement) operand: 2+2 Operator & operands evaluated Call expression: square(2+2) argument: 4 Function (value of operator) called on arguments operator: square (values of operands) function: func square(x) A new frame is created! 4 Calling/Applying: square( x ): Parameters bound to arguments 16 Argument Signature Body is executed in that new environment Return value 8

  24. Multiple Environments in One Diagram! 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  25. Multiple Environments in One Diagram! 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  26. Multiple Environments in One Diagram! square(square(3)) 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  27. Multiple Environments in One Diagram! square(square(3)) 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  28. Multiple Environments in One Diagram! square(square(3)) func square(x) 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  29. Multiple Environments in One Diagram! square(square(3)) func square(x) square(3) 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  30. Multiple Environments in One Diagram! square(square(3)) func square(x) square(3) func square(x) 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  31. Multiple Environments in One Diagram! square(square(3)) func square(x) square(3) func square(x) 3 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  32. Multiple Environments in One Diagram! square(square(3)) func square(x) square(3) func square(x) 3 9 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  33. Multiple Environments in One Diagram! square(square(3)) func square(x) square(3) func square(x) 3 10 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  34. Multiple Environments in One Diagram! square(square(3)) func square(x) square(3) func square(x) 3 10 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  35. Multiple Environments in One Diagram! square(square(3)) 9 func square(x) square(3) func square(x) 3 10 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  36. Multiple Environments in One Diagram! square(square(3)) 9 func square(x) square(3) func square(x) 3 10 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  37. Multiple Environments in One Diagram! 81 square(square(3)) 9 func square(x) square(3) func square(x) 3 11 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  38. Multiple Environments in One Diagram! 81 square(square(3)) 9 func square(x) square(3) An environment is a sequence of frames. func square(x) 3 11 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  39. Multiple Environments in One Diagram! 81 square(square(3)) 9 func square(x) square(3) An environment is a sequence of frames. • The global frame alone func square(x) 3 • A local, then the global frame 11 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  40. Multiple Environments in One Diagram! 1 81 square(square(3)) 9 func square(x) square(3) An environment is a sequence of frames. • The global frame alone func square(x) 3 • A local, then the global frame 11 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  41. Multiple Environments in One Diagram! 1 2 1 81 square(square(3)) 9 func square(x) square(3) An environment is a sequence of frames. • The global frame alone func square(x) 3 • A local, then the global frame 11 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  42. Multiple Environments in One Diagram! 1 2 2 1 1 81 square(square(3)) 9 func square(x) square(3) An environment is a sequence of frames. • The global frame alone func square(x) 3 • A local, then the global frame 11 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  43. Names Have No Meaning Without Environments 1 2 2 1 1 An environment is a sequence of frames. • The global frame alone • A local, then the global frame 12 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  44. Names Have No Meaning Without Environments 1 2 2 1 1 Every expression is evaluated in the context of an environment. An environment is a sequence of frames. • The global frame alone • A local, then the global frame 12 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  45. Names Have No Meaning Without Environments 1 2 2 1 1 Every expression is evaluated in the context of an environment. A name evaluates to the value bound to that name An environment is a sequence of frames. in the earliest frame of the current environment in • The global frame alone which that name is found. • A local, then the global frame 12 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  46. Names Have No Meaning Without Environments 2 1 Every expression is evaluated in the context of an environment. A name evaluates to the value bound to that name An environment is a sequence of frames. in the earliest frame of the current environment in • The global frame alone which that name is found. • A local, then the global frame 12 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  47. Names Have No Meaning Without Environments 2 1 Every expression is evaluated in the context of an environment. A name evaluates to the value bound to that name An environment is a sequence of frames. in the earliest frame of the current environment in • The global frame alone which that name is found. • A local, then the global frame 12 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  48. Names Have No Meaning Without Environments 2 1 Every expression is evaluated in the context of an environment. A name evaluates to the value bound to that name An environment is a sequence of frames. in the earliest frame of the current environment in • The global frame alone which that name is found. • A local, then the global frame 12 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28x%29%3A%0A%20%20%20%20return%20mul%28x,%20x%29%0Asquare%28square%283%29%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  49. Names Have Different Meanings in Different Environments 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. 13 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28square%29%3A%0A%20%20%20%20return%20mul%28square,%20square%29%0Asquare%284%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  50. Names Have Different Meanings in Different Environments A call expression and the body of the function being called are evaluated in different environments 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. 13 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28square%29%3A%0A%20%20%20%20return%20mul%28square,%20square%29%0Asquare%284%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  51. Names Have Different Meanings in Different Environments A call expression and the body of the function being called are evaluated in different environments 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. 13 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28square%29%3A%0A%20%20%20%20return%20mul%28square,%20square%29%0Asquare%284%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  52. Names Have Different Meanings in Different Environments A call expression and the body of the function being called are evaluated in different environments 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. 13 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28square%29%3A%0A%20%20%20%20return%20mul%28square,%20square%29%0Asquare%284%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  53. Names Have Different Meanings in Different Environments A call expression and the body of the function being called are evaluated in different environments 1 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. 13 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28square%29%3A%0A%20%20%20%20return%20mul%28square,%20square%29%0Asquare%284%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

  54. Names Have Different Meanings in Different Environments A call expression and the body of the function being called are evaluated in different environments 1 2 1 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. 13 http://pythontutor.com/composingprograms.html#code=from%20operator%20import%20mul%0Adef%20square%28square%29%3A%0A%20%20%20%20return%20mul%28square,%20square%29%0Asquare%284%29&cumulative=true&curInstr=0&mode=display&origin=composingprograms.js&py=3&rawInputLstJSON=%5B%5D

Recommend


More recommend