zoukankan      html  css  js  c++  java
  • 7ch

    。。安软件的时候故障重启,之前写的丢失了,不补了,续着写。

    dict.iter* 方法iteritems(),iterkeys(),itervalues()与它们对应的非迭代方法一样,不同的是它们返回一个迭代子(iterator),而不是一个列表。

    这里返回的iterator不可以直接使用,我们可以通过list()也可以通过for来访问其中的元素。

    dict.setdefault(key, default = None)和方法set()类似,但如果字典中不存在key键,由dict[key]=default为它赋值。

    dict.update(dict2)将字典dict2的键值对添加到字典dict中

    内建函数sorted()可以说是专门为迭代子(iterator)设置的,

    keys(),items(),values()返回列表,(接下来的一段翻译出错,贴出原文)

    Currently, the keys(),items(), and values()methods return lists. This
    can be unwieldy if such data collections are large, and the main reason why
    iteritems(), iterkeys(),  and itervalues() were  added  to  Python  in
    2.2.  They  function  just  like  their  list  counterparts  only  they  return  iterators,
    which by lazier evaluation, are more memory-friendly. In Python 3, each of the
    iter*()methods replaces their non-iterator counterparts and the iter*()
    names are no longer supported. The new keys(),values(), and items()all
    returnviews—these are like a combination of a set and an iterator. You can
    iterate through them one-at-a-time, but each such collection behaves like a set.

    而中文意思可以说完全曲解的愿意……

    我打开了python3测试,果然dict对象已经没有了iter*系列的方法。

    7.5字典的键

    7.5.1 不允许一个键对应多个值,多次赋值会取最后一次。

    7.5.2键必须是可哈希(hashnable)的(感觉上一条多余啊,可哈希的键当然不能对应多个值,这样用哈希值才能找到对应的值啊)

    值相同的数字的哈希值是一样的,比如1.0和0。

    实现了__hash__()方法的可变对象也是可哈希(hashnable)的,

    使用元组作为字典的键时,元组中必须只包括像数字和字符串这样的不可变参数。

    例7.1这个程序用于管理系统的用户信息:登录(这本书的翻译真的有很大问题,后来了解到是有一个人忽悠一个社区去翻译这个文章,

    然后挂自己名出版,难怪,可能就是随便赶出来的……)

    7.6集合类型
    set(),frozenset()分别创建可变和不可变的集合。

    内建方法:

    add(),updagte(),remove()

     7.7集合类型操作符

    1成员关系:

    in, not in

    2集合等价:

    == , !=

    3子集/超集:

    > , >=, <, <=

    4逻辑关系操作符:

    | & - ^

    仅使用于可变集合的操作符:

    |=等价于update()

    &=等价于intersection_update()

    -=等价于difference_update()

    ^=等价于symmetric_difference_update()

    内建函数

    len()

    set(),frozenset()参数必须是可迭代的

    内建方法

    (比较繁琐,这里不给出)

  • 相关阅读:
    关于MySQL死锁
    随手一记,maven打包
    js生成带logo的二维码
    java生成带logo的二维码
    关于网页中文本域高度自动适应问题,参考微信回复
    从git上拉下来的严选weex项目demo
    补装老版本的Java SE
    新MBP使用git命令时启用xcode的终端log
    电脑出现“损坏的图像”窗口提示dll没有被指定在Windows上运行如何解决
    不同浏览器隐藏默认表单样式
  • 原文地址:https://www.cnblogs.com/autoria/p/4470999.html
Copyright © 2011-2022 走看看