CS 61A: SICP - week2 - 1

·  阅读 101

一 Print and None

  1. 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
     
    
  2. Pure Functions & Non-Pure Functions

     Pure Functions: just return values
     Non-Pure Functions: have side effects
    

二 Multiple Environments

  1. Life Cycle of a User-Defined Function

    Def statement:  A new function is created!
                    Name bound to that function in the current frame
                    
    Call expression: Operator & operands evaluated
                     Function (value of operator)called on arguments (values of operands)
    
    Calling/Applying: A new frame is created!
                      Parameters bound to arguments Body is executed in that new environment
                      
    
  2. Names Have No Meaning Without 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.
    
  3. write test in doctest

     """<description>
     >>> q,r = divide_exact(2013,10)
     >>> q
     201
     >>> r
     3
     """
     
    

    in cmd input

     python -m doctest -v **.py
     
    
  4. Conditional Statements 4.1 Statements

    A statement is executed by the interpreter to perform an action
    

image.png

4.2 Compound Statements

image.png

4.3 Conditional Statements

image.png

False values in Python: False, 0, '', None
True values in Python: Anything else (True)

5. Iteration 5.1 While Statements

Execution Rule for While Statements:
1. Evaluate the header’s expression.
2. If it is a true value, execute the (whole) suite, then return to step 1. 
分类:
后端
标签:
分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改