zoukankan      html  css  js  c++  java
  • python中生成字典

    1、

    >>> a = {"a":111,"b":222,"c":333,"d":444}
    >>> a
    {'a': 111, 'b': 222, 'c': 333, 'd': 444}
    >>> len(a)
    4
    >>> type(a)
    <class 'dict'>

    2、

    >>> a = dict((("a",111),("b",222),("c",333),("d",444)))
    >>> a
    {'a': 111, 'b': 222, 'c': 333, 'd': 444}
    >>> len(a)
    4
    >>> type(a)
    <class 'dict'>

    3、

    >>> a = dict(a = 111, b = 222, c = 333, d = 444)
    >>> a
    {'a': 111, 'b': 222, 'c': 333, 'd': 444}
    >>> len(a)
    4
    >>> type(a)
    <class 'dict'>

    4、

    >>> a = {}
    >>> a["a"] = 111
    >>> a["b"] = 222
    >>> a
    {'a': 111, 'b': 222}
    >>> len(a)
    2
    >>> type(a)
    <class 'dict'>

    5、

    >>> a = dict(zip(("a","b","c","d"),(111,222,333,444)))
    >>> a
    {'a': 111, 'b': 222, 'c': 333, 'd': 444}
    >>> type(a)
    <class 'dict'>
    >>> len(a)
    4

    6、

    >>> a = {}
    >>> a = a.fromkeys(("a","b","c","d"),"xxxx")
    >>> a
    {'a': 'xxxx', 'b': 'xxxx', 'c': 'xxxx', 'd': 'xxxx'}
    >>> b = {}
    >>> b = a.fromkeys(range(20),"xxxx")
    >>> b
    {0: 'xxxx', 1: 'xxxx', 2: 'xxxx', 3: 'xxxx', 4: 'xxxx', 5: 'xxxx', 6: 'xxxx', 7: 'xxxx', 8: 'xxxx', 9: 'xxxx', 10: 'xxxx', 11: 'xxxx', 12: 'xxxx', 13: 'xxxx', 14: 'xxxx', 15: 'xxxx', 16: 'xxxx', 17: 'xxxx', 18: 'xxxx', 19: 'xxxx'}
  • 相关阅读:
    Sass代码重用----Sass继承
    Sass代码重用
    Scss基本运算-------颜色运算
    Scss基本运算-------字符运算
    Scss基本运算-------数字运算
    7.Scss的基本运算
    6.Scss注释
    css横竖屏判断
    禁止页面缩放及meta便签常用属性
    微信小程序 错误记录
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14449331.html
Copyright © 2011-2022 走看看