Python Another Digest
来源:互联网 发布:云数据加密传输运营商 编辑:程序博客网 时间:2024/06/04 00:29
- Python Another Digest
- 再读python
- Dict
- 杂项
- 再读python
csdn 居然支持 markdown了, 强烈点个赞!
Python Another Digest
python用作工作语言也快一年了,当年接触的时候也就跟着老师快速过了一周的PPT, 从来没有系统地买过一本Python书细细阅读过正好室友有本python基础教程,趁着这个机会炒一次回锅肉!
再读python
一些曾经不曾注意的细节
Dict
- python collection中的超实用类:Counter, deque, OrderedDict(按插入顺序)
- Dict的key可为int(以前都不知道), 同lua table; 但key一定是 immutable (不可变)
- “%(Ceil)” % phonebook 会自行抽取phonebook[“Ceil”]当做值替换,template正是如此,{{ count }}
dict, list 中每项都是指针, 必须deepcopy 才能隔离原值dict.iteritems() 返回迭代器.items()返回列表, 前者迭代更高效(不用生成列表)dict.popitem() 随机弹出一个
杂项
- 比较运算: x == y 比值 x is y 比指针;
- 上文用C类比为: *x == *y; x == y 比较指针本身
- zip 打包(联合) 多个list, 长度已短为准;
zip([1,2], ['a', 'b', 'c']) -->[(1, 'a'), (2, 'b')]
- for index, string in enumerate(strings): index 代表第几个(从零开始), 再也不用 index = 0 在循环里 index += 1了!
- reversed() 返回迭代器, sorted() 返回列表
for ...: ... breakelse: # 在for未触发break时 执行 ...
- del x 只删引用,x指向的内存只能 garbage collection
- exec 可把string 当python 代码执行,为了安全用scope作为sandbox
scope = {} exec string in scope
- callable(x) 判断 x 是否可调用; ( 3.0 更改为 hasattr(func, all)
- help(x) 会把 x 的 docstring, func(params) 全打印出来
- def print_params( * params, **param_dict) 前者元组, 后者字典
- vars() 返回当前作用域;locals 局部作用域;globals全局作用域
- 函数嵌套多用于闭包(closure) = func + 作用域
- 多态, duck typing, class中定义德method绑定了self
- __method 私有方法被翻译为 _classname__method
- issubclass(superclass, subclass) 判断是否继承关系
- bases 得到基类(们,当多重继承时)
try:except ( , ) as e: # 获得异常变量 raise # 把异常交给上层函数else: # 没有触发异常时执行finally: # 总会执行
0 0
- Python Another Digest
- Python Another Digest(2)
- Python Another Digest(3)
- a digest of python maillist
- Digest
- Embedding Python in Another Application
- another
- ANother
- another
- Yet Another Sudoku Solver in Python
- [leetcode: Python]572. Subtree of Another Tree
- Python unittesting: run tests in another module
- 嵌套python解释器(Embedding Python in Another Application)
- News Digest
- News Digest
- RFC Digest
- Digest authentication
- Digest authentication
- Scala学习笔记4--函数值
- ubuntu 64位 安装 ia32-libs
- 第二章 Qt常用工具的介绍
- ubuntu14.04 配置安装 wineQQ 2013
- 顶级offer的标准:有内部培养+晋升机会
- Python Another Digest
- Linux应用札记【三】—Unity桌面环境使用技巧点滴
- ESQL查询之简单的Oracle数据库查询测试
- 网络加载图片
- cortex_m3_stm32嵌入式学习笔记(二十三):红外遥控实验(输入捕捉+解码)
- .net利用Attribute简单实现AOP
- BZOJ 1263 SCOI2006 整数划分 高精度
- 学习stanford公开课 Developing iOS8 Apps with Swift 笔记(一)
- Android将应用log信息保存文件