CS61A 学习笔记(8.10)

Names and the Environment

  • bind

    • 编程语言中提供了使用name来引用计算对象的方法。如果某个name被赋予value,我们称该名称绑定到值.在python中我们可以用赋值语句来对值进行绑定
  • environment

    • 将名称绑定到value并通过名称来检索这些值意味着解释器必须维持存储来跟踪namevaluebind,这种存储称为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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值