•        Python : 3.7.3
  •          OS : Ubuntu 18.04.2 LTS
  •         IDE : pycharm-community-2019.1.3
  •       Conda : 4.7.5
  •    typesetting : Markdown

code

coder@ubuntu:~$ source activate py37
(py37) coder@ubuntu:~$ ipython
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: my_dict = {
...: "子": "鼠",
...: "丑": "牛",
...: "寅": "虎",
...: "卯": "兔",
...: "辰": "龙",
...: "巳": "蛇",
...: "午": "马",
...: "未": "羊",
...: "申": "猴",
...: "酉": "鸡",
...: "戌": "狗",
...: "亥": "猪"
...: } In [2]: my_dict.__len__()
Out[2]: 12 In [3]: exit
(py37) coder@ubuntu:~$ conda deactivate
coder@ubuntu:~$

source_code

def __len__(self, *args, **kwargs): # real signature unknown
""" Return len(self). """
pass

resource

  • [文档 - English] docs.python.org/3
  • [文档 - 中文] docs.python.org/zh-cn/3
  • [规范] www.python.org/dev/peps/pep-0008
  • [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
  • [源码] www.python.org/downloads/source
  • [ PEP ] www.python.org/dev/peps
  • [平台] www.cnblogs.com
  • [平台] gitee.com


Python具有开源、跨平台、解释型、交互式等特性,值得学习。

Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。

代码的书写要遵守规范,这样有助于沟通和理解。

每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

Python3基础 dict __len__ 统计键值对的数量的更多相关文章

  1. Python3基础 dict setdefault 根据键查找值,找不到键会添加

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. Python3基础 dict fromkeys 多个键对应相同的值

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. Python3基础 dict in/not in 查询一个字符是否指定字典的键或者值

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. Python3基础 dict keys+values 循环打印字典中的所有键和值

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. Python3基础 dict get 在查询不存在的键时,返回指定的内容

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. Python3基础 dict 推导式 生成10以内+奇数的值为True 偶数为False的字典

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. Python3基础 dict pop 弹出指定键的项

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Python3基础 dict 创建字典 空字典

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 访问列表指定索引值的元素

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

随机推荐

  1. lvm逻辑卷扩容报错解决

    报错: [root@centos21 space]# resize2fs /dev/centos/root resize2fs (-Dec-) resize2fs: Bad magic number ...

  2. clipse调试web项目配置调试配置——没有Server

    文章:eclipse环境下如何配置tomcat(包含没有Server解决办法) 地址:https://blog.csdn.net/TimliangL/article/details/78882566

  3. 第一次使用Git(常用的dos命令整理)

    在使用git的过程中,有许多dos命令也要会用才行 Git 工具分类 命令行 bash.cmd.power shell GUI Git GUI.GitHub Desktop IDE 集成 Visual ...

  4. Codeforces E. Interesting Array(线段树)

    题目描述: D. Interesting Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard ...

  5. http请求头出现provisional headers are shown

    http请求头出现provisional headers are shown Provisional headers are shown provisional 详细用法>> 英 [prə ...

  6. php数组打乱顺序

    shuffle() PHP shuffle() 函数随机排列数组单元的顺序(将数组打乱).本函数为数组中的单元赋予新的键名,这将删除原有的键名而不仅是重新排序. 语法: bool shuffle ( ...

  7. docker-compose部署gitlab

    一.安装docker-compose步骤可参考本博客其他文章 二.这里的ssl证书是使用letsencrypt生成,可参考文档https://my.oschina.net/u/3042999/blog ...

  8. Backpressure & Elastic Scaling

    spark.streaming从不稳定到稳定状态,解决数据量接收数据时突然变大,使得无法及时处理数据,稳定性得到保证 开启方式: spark.streaming.backpressure.enable ...

  9. web自动化测试-selenium多表单切换

    一.概述 1.在web应用中会经常遇到frame/iframe表单嵌套页面的应用 2.WebDriver只能在一个页面上对元素进行识别与定位 3.对于frame/iframe表单内嵌的页面上元素无法识 ...

  10. CF 768B

    CF 768B题意:In each operation Sam must remove any element x, such that x>1, from the list and inser ...