Ubuntu18.04 Python3环境
默认python3已经安装了, 可能是安装其他应用的时候因为依赖关系安装的.
安装pip3, 先sudo apt update 一下, apt-cache search python3-pip 看看有没有, 如果没有的话检查一下/etc/apt/sources.list 是否正确
然后通过 sudo apt install python3-pip 安装
常用的通过pip3安装的package: pymongo,
常用语法
合并两个Dictionary
x = {'aa':1, 'bb':2, 'cc':3} y = {'aa':5, 'xx':6, 'yy':7} z = {**x, **y} x.update(y) print(x) # 输出 {'aa': 5, 'bb': 2, 'cc': 3, 'xx': 6, 'yy': 7} {'aa': 5, 'bb': 2, 'cc': 3, 'xx': 6, 'yy': 7}
两种方法都可以实现dictionary合并, 前者不会修改原先两个dictionary的值
逻辑判断
# 空, 非空 if (x is None) if (not x is None) # dictionary是否包含某key if ('name' in x.keys()) if (not 'name' in x.keys())
.