摘要: 在阅读 python 相关书籍中, 对其进行简单的笔记纪要. 旨在注意一些细节问题, 在今后项目中灵活运用, 并对部分小 notes 进行代码标注.
35 使用多个列表. 用法:
36 比较运算符两边各添加空格, 便于可读性. 用法: if age> 40:37 dict 修改值, 用法: dict['key'] = value38 dict 删除键值对, 用法: del dict['key']39 字典的遍历, 用法:
40 字典列表, 用法:
41 字典中存储列表, 用法:
42 字典中存储字典, 用法:
43 input 接收用户输入, 用法: message = input('user input some values!')44 % 取模运算判断奇偶, 用法:
45 while 循环的常规用法:
46 while 循环使用标志的用法:
- flag = True
- while flag:
- message = input(prompt)
47 列表之间移动元素, 用法:
- while list[]:
- newlist.append(list[].pop())
48 删除特定的元素, 用法:
49 形参与实参的理解, 用法:
50 位置参数, 用法:
51 关键字实参是传递函数的名称 - 值对, 用法:
52 形参设置默认值, 用法: def describe(name='lisi',age):53 返回值, 用法:
54 列表参数, 用法:
55 传递任意参数, 用法: def cats_name(*cats): # 可以传递多个形参 56 位置实参和任意数量实参:
57 任意实参和关键字实参, 用法:(cats.py)
58 导入整个模块, 用法:
- import cats
- cats.cats_name(para1,para2,para3,newname=para4,...)
59 导入特定的函数, 用法: from nltk import map_tag as mt60 导入模块所有函数, 用法: from nltk import *61 形参默认时, 两边不能为空, 用法: def function_name(parament_0,parament_1='default')62 类的命名是驼峰型即首字母大写. 63 __init__(self,papa1,para2): 避免 python 默认方法跟普通方法名称冲突, self 必不可少, 必须位于其他形参的前面, 指向实例本身. 64 类的继承, 用法:
65 几种类的导入方式, 用法:
66 读取文本文件, 并删除字符串始末空白, 用法: my_str = line.strip()67 opem() 自动创建文件路径, 若路径不存在时候. 68 异常代码块: try-except69 split() 创建单词列表
70 存储数据 json.dump() 和 json.load()
关注小编私信 [学习资料] 领小编精心准备的海量 Python 学习资料
来源: http://www.92to.com/bangong/2018/07-11/33985522.html