python(3)methods & tips~
来源:互联网 发布:mac谜案处by虎喵喵 编辑:程序博客网 时间:2024/06/06 00:54
Methods:
isinstance(a,b):
类型判断方法。
a是要判断的数据,b是类型(eg. str, Iterable)
enumerate:
把一个list变成dict
filter:
def not_empty(s): return s.strip()def remove_space(points_tuple):return filter(not_empty, points_tuple)
map/reduce:
当需要对列表中的每一个元素进行同样操作的时候用map,reduce 应用于有规律的累计过程
返回list
sorted:
感觉很强大,可以排列字符串,按他们的ASCII码值来排列
递归:尾递归问题,写成廖雪峰python教程中的写法,虽然对python还是会溢出,但是写
def fact(n): return fact_iter(n, 1)def fact_iter(num, product): if num == 1: return product return fact_iter(num - 1, num * product)
函数参数:
分为四种,必选参数,默认参数,可变参数,关键字参数。如果在传参时候都出现的话要用这样的顺序来写
可变参数用法:*+list/tuple 实际函数接收的是一个tuple参数个数不定,常用的形参写法 *args
关键字参数:** +dict 关键字参数传入的时候用 key = value的形式,常用形参写法 *kw
两种均可以直接传参进入
tips:
range()用的很多,两个变量和一个变量的方法
slice 是左闭右开[a:b]可用于list/tuple
区分L[-2:-1] & L[-2:] L[:2] & L[1:2]
L[::2]每两个取一个
generator 理解的不好,先不纠结挖个小坑,等用到了、会用了再回来填。
0 0
- python(3)methods & tips~
- python tips(3)
- python tips(1~2)
- Python学习tips(1)
- Python学习tips(2)
- python tips
- Python tips
- python tips
- Python Tips
- python tips
- python tips
- Python tips
- Python Tips
- Python Tips
- Python-Tips
- Python Tips
- Python Tips(Python小知识点)
- Python Attributes and Methods
- Javascript的对象
- 文件进行 MD5 加密的意义
- 关于cfile fopen fopen_s 在windows vista win7 win8 win 10系统盘目录创建文件失败解决方案-- fopen 创建文件失败
- 好多的东西需要掌握!
- oracle基础
- python(3)methods & tips~
- 关于sizeof()函数
- 详解spring: 事务属性的设置
- win32程序判断windows系统(是否为win7或是更高版本)
- NYOJ 37 回文字符串
- 浅谈贝贝游戏数据加密解密方式
- 10月20日 html学习笔记(2)
- listview中如何将某一个item显示成其它的样式
- 爱与失落