1 Star 0 Fork 0

巧克力ovo/PythonLearn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
4-1.py 772 Bytes
一键复制 编辑 原始数据 按行查看 历史
wlt 提交于 3个月前 . 4
#connected with 3-1
#字典:无序可变 包含键值对
dic={}#空字典
list1=[1,2,3]
list2=["A","B","C"]
dic=dict(zip(list1,list2))#允许初始赋值 zip:拉链 第一个参数:key 第二个:value
print(dic)
dic=dict.fromkeys(list1,"A")#允许初始赋值 fromkeys:从键创建字典
print(dic)
dic={tuple(list1):list2}
print(dic)
dic={"name":"Tom","age":18}
print(dic)
#dic.update(dic2)//dict(dict1.items()|dict2.items()) 添加/合并
#可使用key值访问 使用索引或.get
#遍历
for item,value in dic.items():
print(item,value)
import random
#随机生成字典
randomdic={i:random.randint(1,100) for i in range(10)}
print(randomdic)
#集合:无序不可重复 创建:{} add() remove() discard() pop() clear() copy() &取交集 |取并集 -取差集
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chocolate-ovo/python-learn.git
git@gitee.com:chocolate-ovo/python-learn.git
chocolate-ovo
python-learn
PythonLearn
master

搜索帮助