📂
CS-NoteBook
  • Introduction
  • CS144
    • concise introduction to Internet
      • 1.1 Networked Applications
      • 1.2 The 4 Layer Internet
      • 1.3 IP
      • 1.4 A Day in the Life of a Packet
      • 1.5 Principle: Packet Switching
      • 1.6 Principle:Layering
      • 1.7 Principle: Encapsulation
      • 1.8 Byte order and packet formats
      • 1.9 name and addresses:IPv4
      • 1.10 Longest Prefix Match for Link Layer
      • 1.11 Address Resolution Protocol(ARP)
      • 1.12 Summary
    • Transport Layer
      • 2.1 The TCP Service Model
      • 2.2 UDP service model
      • 2.3 ICMP(Internet Control Message Protocol 互联网报文控制协议)
      • 2.4 The End-to-End Principle
      • 2.5 Error Detection:3 schemes (Checksum,CRC and MAC)
      • 2.6 Finite State Machines(有限状态机)
      • 2.7 Flow Control
      • 2.8 Sliding window
      • 2.9 Retransmission Strategies
      • 2.10 TCP Header
      • 2.11 TCP Setup and Teardown
      • 2.12 Recap
    • Package Switching
      • 3.1 The history of Internet
      • 3.2 What is packet switching
      • [3.3 End-to-end delay and Queueing delay
      • 3.4 Playback Buffer(回放缓存区)
  • CS 61C
    • 1.4 C Memory Mangement, Usage
    • 1.5 Intro to Assembly Language, MIPS Intro
    • 1.5 extra bits operation
  • CS 61B
  • CS 61A
    • Function
    • Names
    • The Art of the Function
    • Control
    • Higher-Order Function
    • Recursive Function
    • List
    • Non-Local Assignment
    • Iterators
    • Objects
    • Data Abstraction
    • OOP
    • Inheritance
    • Representations
    • Decomposition
    • Scheme
    • Exceptions
    • Calculator
    • Interpreters
    • Declarative_Programming
    • Table
    • Aggregation
      • More_recursion
    • Databases
    • Distributed_Data
    • Tail Recursion
    • Exercises
      • lab00
      • lab01
      • hw01
      • tree Recursion example -- give Change
  • The Web DevelopMent Bootcamp
    • html5
    • css
    • bootstrap3
    • bootstrap4
    • javascript expression
    • javascript function
Powered by GitBook
On this page
  • string 是 对象
  • Object can change
  • tuples
  • 相同与改变
  • 一些陷阱

Was this helpful?

  1. CS 61A

Objects

  • 对象代表着信息

  • 它包含数据和行为,捆绑在一起以创建抽象

  • 对象可以代表事物,但也可以代表属性、交互和过程

  • 对象的类型称为类;类是 Python 中的头等值

  • 面向对象的程序设计

    • 组织大型程序的比喻

    • 可以改进程序组成的特殊语法

  • Python 中的每个值都是对象

    • 所有对象都有属性

    • 许多数据的处理是通过对象方法

    • 函数只做一件事情,但对象做多个事情(做每个事情都是一个函数)

string 是 对象

  • string 有属性

s = "Hello"
s.upper()    # 'HELLO'
s.lower()    # 'hello'
s.swapcase() # 'hELLO'

a = 'A'
ord(a)       # 65  对应的 ACSII 数
hex(ord(a))  # '0x41' 是 65 对应的 16进制

Object can change

  • 所有引用同一对象的名称都会受到变化的邮箱

    • list & dictionaries

tuples

  • 不可改变的序列

>>> (3,4) + (5,6)
(3,4,5,6)
>>> {(1,2):3}
{(1,2) : 3}
>>> {[1,2]:3}
error
  • 他能保护 values 不被改变

>>> turtle = (1, 2, 3)
>>> ooze()
>>> turtle
(1, 2, 3)

>>> list = [1, 2, 3]
>>> ooze()
>>> list
['Anything could be inside']
  • 如果 tuple 内有可改变的序列,它的元素也有可能发生改变

>>> s = ([1, 2], 3)
>>> s[0] = 4
ERROR
>>> s[0][0] = 4
([4, 2], 3)

相同与改变

  • 只要我们不修改对象,一个复合对象就是它各个部分的总和

  • 除了组成复合数据对象的各个部分之外,复合数据对象本身还有一个“标识”

  • 即使我们改变了它的内容,复合数据对象这个“标识”还是未改变。

  • 如果有两个 list 恰好有相同的内容,但他们是不同的。(复合数据对象这个“标识”不一样)

A is B

  • 对应相同的 object 则相同 (类似 java 的 == ) A == B

  • 对应相同的 value 则相同 (类似 java 的 equals )

>>> [1,2] == [1,2]
True
>>> [1,2] is [1,2]
False

一些陷阱

  • 默认实参值是函数的一部分,不是由调用生成的

def f(s=[]):
    s.append(5)
    return len(s)

f()     # 1
f()     # 2
f([1])  # 2
PreviousIteratorsNextData Abstraction

Last updated 4 years ago

Was this helpful?

defaultArgs