python创建字典的方法

本文阅读 1 分钟
首页 › Python笔记 › 正文
  1. 直接创建

    dict = {'name':'earth', 'port':'80'}
  2. 工厂方法

    items=[('name','earth'),('port','80')]
    dict2=dict(items)
    dict1=dict((['name','earth'],['port','80']))
  3. fromkeys()方法

    dict1={}.fromkeys(('x','y'),-1)
    dict={'x':-1,'y':-1}
    dict2={}.fromkeys(('x','y'))
    dict2={'x':None, 'y':None}
杨氏矩阵查找
« 上一篇 04-10
Python合并两个有序列表
下一篇 » 04-10

发表评论