36 Matching Annotations
  1. Dec 2020
    1. One way to create a dictionary is to start with the empty dictionary and add key-value pairs. The empty dictionary is denoted {}

      创建字典的一种方法是从空字典开始并添加键-值对。空字典表示为{}

    2. mapping type

      映射类型

    1. Cloning Lists

      克隆列表用切片 b = a【:】

    2. a new list

      切片会创造一个新的list

    3. If we want to modify a list and also keep a copy of the original, we need to be able to make a copy of the list itself, not just the reference. This process is sometimes called cloning,

      如果我们想修改一个列表,同时保留原始列表的副本,我们需要能够复制列表本身,而不仅仅是引用。这个过程有时被称为克隆,

    1. Changes made with one alias affect the other

      a = 1 b = a 这时候 a b = 1

      b = 2 print(a) a = 2

      a的值会跟随着吧的变化而变化

    2. Because the same list has two different names, a and b, we say that it is aliased

      因为同一个列表有两个不同的名称,a和b,我们说它有别名

    3. Aliasing

      别名 把a 赋值给b 这样a b 引用同一个object

    1. a and b have the same value but do not refer to the same object.

      list:a和b有相同的值,但不引用相同的对象 string : 是同一个object

    2. The is operator will return true if the two references are to the same object

      如果两个引用指向同一个对象,则is操作符将返回true

    3. Objects and References

      对象和引用

    1. We can even insert elements into a list by squeezing them into an empty slice at the desired location

      利用切片【1:1】来插入值

    2. We can also remove elements from a list by assigning the empty list to them.

      可以用【】来remove list里面的元素

    3. assignment with the slice operator

      切片和赋值的结合

    4. Lists are Mutable

      列表是可变的

    1. In Python, every object has a unique identification tag

      在Python中,每个对象都有一个唯一的标识标签

      每个object 在堆内存里都有一个id 空间

    2. it refers to a completely new list

      create one new list 就像 new string 一样,以前的list和string 还在

    3. Concatenation and Repetition

      list用 + 连接2个或多个list 用* 使list重复出现

    1. [56, 57, "dog"],

      只有顶级项目返回True。57在子列表中。

    2. in and not in

      in and not in 判断给的object是否在 list里面 in : true not in : false

    3. List Membership

      列表的隶属关系

    1. alist[2][0])

      print(alist[2] [0]) 先取index = 2 “cat“” 再 取cat 的第一位

    2. Accessing Elements

      访问元素 负索引值将从右侧而不是从左侧定位项。

    3. The expression inside the brackets specifies the index.

      【】里面是index

    1. Lists are similar to strings, which are ordered collections of characters, except that the elements of a list can have any type and for any one list, the items can be of different types.

      列表类似于字符串,字符串是有序的字符集合,不同之处在于列表的元素可以是任何类型,而且对于任何一个列表,项可以是不同类型。