dictionary

python notes

放肆的年华 提交于 2020-11-02 10:44:25
python notes 一、python的定义 :Python 是一个高级动态、解释性、编译性、互动性和面向对象的脚本语言。 二 、python的特点: 1、简单灵活 2、 开源免费 3、 跨平台 4、 高级动态 5、 支持命令式编程 6、函数式编程 7、 面向对象编程 三、python的基本数据类型 标准数据类型:数字(Number)、字符串(String)、列表(List)、元组(Tuple)、集合(Set)和字典(Dictionary); (1):不可变数据:Number(数字)、String(字符串)、Tuple(元组); (2):可变数据:List(列表)、Dictionary(字典)、Set(集合)。 1、数字类型: ```python >> > a = 10 #整型 >> > b = 2.12 #浮点型 >> > c = True #bool型 >> > d = 1 + 2j #complex(复数型) >> > print ( type ( a ) ) #单个输出 < class 'int' > >> > print ( type ( a ) , type ( b ) , type ( c ) , type ( d ) ) #全部输出 < class 'int' > < class 'float' > < class 'bool' > < class

Python经典习题100例(附PDF下载地址)

青春壹個敷衍的年華 提交于 2020-11-01 20:30:48
pk哥肝了一个月,从两本书《Python基础教程(第3版)》和《流畅的Python》里把知识点进行了汇总,整理成了 100 道 Python习题, Python 100题我已经整理成了 PDF 文档,需要文档的可以关注下方公众号「Python知识圈」并回复:“ 100 ” 获取文档。 关注后回复:“ 100 ” 获取 pdf 文档 作者:pk哥 公众号:Python知识圈 Python基础习题 怎么计算2的3次方 解法1:直接用运算符 ** >>> 2**3 8 解法2:用函数 pow >>> pow(2,3) 8 怎么找出序列中的最大最小值? 用内置函数 max 和 min >>> l = (123, 888, 666) >>> max(l) 888 >>> min(l) 123 怎么将字符列表转为字符串 用 join 方法,合并序列的元素 >>> l = [ 'Python' , 'Circle' , 'is' , 'ok' ] >>> j = ' ' .join(l) >>> j 'Python Circle is ok' 怎么快速打印出包含所有 ASCII 字母(大写和小写)的字符串 用 string 模块的方法 >>> import string >>> string.ascii_letters

《Python Cookbook 3rd》1.6:字典中的键映射多个值

心已入冬 提交于 2020-11-01 19:13:36
字典中的键映射多个值 问题 怎样实现一个键对应多个值的字典 (也叫 multidict )? 解法 一个字典就是一个键对应一个单值的映射。如果你想要一个键映射多个值,那么你就需要将这多个值放到另外的容器中,比如列表或者集合里面。比如,你可以像下面这样构造这样的字典: d = { 'a' : [1, 2, 3], 'b' : [4, 5] } e = { 'a' : {1, 2, 3}, 'b' : {4, 5} } 选择使用列表还是集合取决于你的实际需求。如果你想保持元素的插入顺序就应该使用列表,如果想去掉重复元素并且不关心元素的顺序问题,就使用集合。 你可以很方便的使用 collections 模块中的 defaultdict 来构造这样的字典。defaultdict 的一个特征是它会自动初始化每个 key 刚开始对应的值,所以你只需要关注添加元素操作了。比如: from collections import defaultdict d = defaultdict(list) d['a'].append(1) d['a'].append(2) d['b'].append(4) d = defaultdict(set) d['a'].add(1) d['a'].add(2) d['b'].add(4) 需要注意的是, defaultdict 会自动为将要访问的键

英语学习-华尔街英语学习法

别来无恙 提交于 2020-10-31 10:01:50
Learning Cycle:学习循环 When you listen, do you : try to understand 100% ? listen for the main idea ? What the goal of “Listen”? What do you find difficult in “Listen”? What’s the solution ? When you pronounce, do you: focus on the word? the sentence?  the sentence + situation ?  the sentence +situation + emotion? What's the goal of “Pronounce”?What do you find difficult in “Pronounce” ?What's the solution? 句子声音+情景+情感 When you read, do you:  focus on the spelling of the words or the sound ? try to write down every sentence? What's the goal of “Read ”? What do you find difficult in “Read”