Names and the Environment
-
bind
- 编程语言中提供了使用name来引用计算对象的方法。如果某个name被赋予value,我们称该名称绑定到值.在python中我们可以用赋值语句来对值进行绑定
-
environment
- 将名称绑定到value并通过名称来检索这些值意味着解释器必须维持存储来跟踪name、value、bind,这种存储称为environment
-
variable names or variables
-
python中 names 主要称为变量名或变量(执行程序的过程中绑定到不同的值)
-
EX1:利用单个语句同时对多个变量进行赋值
-
EX2:利用单个语句对两个变量绑定的值互换
-
EX1:
>>> area, circumference = pi * radius * radius, 2 * pi * radius
>>> area
314.1592653589793
>>> circumference
62.83185307179586
EX2:
>>> x, y = 3, 4.5
>>> y, x = x, y
>>> x
4.5
>>> y
3
说明:对于多重赋值,等号"="
右侧的所有表达式会先进行evaluate,再对等号"="
左侧的变量进行赋值
Expression
-
Types of Expressions
-
primitive expressions
- representing numbers may be combined with mathematical operators to form a compound expression
-
call expressions
- applies a function to some arguments
-
-
Evaluating Nested Expressions
-
The process followed by the interpreter (evaluating nested expressions)
-
1.Evaluate the operator and operand subexpressions(运算符子表达式和操作符表达式)
-
operator:An operator is a symbol (such as +, x, etc.) that represents an operation.
-
types:unary and binary
-
categories
-
Arithmetic operators.
-
Comparison (or Relational) operators.
-
Assignment operators.
-
Logical operators.
-
Bitwise operators.
-
Membership operators.
-
Identity operators.
-
-
-
operand:the quantity on which an operation is to be done.
-
-
2.Apply the function that is the value of the operator subexpression to the arguments that are the values of the operand subexpressions.
-
-