[学习笔记]Python 常用函数
2017-11-25 23:54
821 查看
isinstance(…)
isinstance(object, class-or-type-or-tuple) -> bool
Return whether an object is an instance of a class or of a subclass thereof. With a type as second argument, return whether that is the object’s type. The form using a tuple, isinstance(x, (A, B, …)), is a shortcut for isinstance(x, A) or isinstance(x, B) or … (etc.).
Random生成随机数
练习:生成8位数随机密码,要求大小写数字加下划线
isinstance(object, class-or-type-or-tuple) -> bool
Return whether an object is an instance of a class or of a subclass thereof. With a type as second argument, return whether that is the object’s type. The form using a tuple, isinstance(x, (A, B, …)), is a shortcut for isinstance(x, A) or isinstance(x, B) or … (etc.).
for s in [u'abc', 'abc']: print isinstance(s, str) print isinstance(s, basestring) print isinstance(s, unicode) #输出结果 False True True True True False
Random生成随机数
函数 | 说明 |
---|---|
choice(seq) | 从序列的元素中随机挑选一个元素,比如random.choice(range(10)),从0到9中随机挑选一个整数。 |
randrange ([start,] stop [,step]) | 从指定范围内,按指定基数递增的集合中获取一个随机数,基数缺省值为1 |
random() | 随机生成下一个实数,它在[0,1)范围内。 |
shuffle(list) | 将序列的所有元素随机排序 |
uniform(x, y) | 随机生成下一个实数,它在[x,y]范围内。 |
randint(self,a,b) |
import random import string list=[] for i in range(1,4): a=random.choice(string.digits) b=random.choice(string.lowercase) c=random.choice(string.uppercase) list.append(a) list.append(b) list.append(c) del list[0:2] #取九个元素删掉两个 #print list list.append("_") #加上下划线 random.shuffle(list) #随机排序 password=''.join(list) #拼接成字符 print password
相关文章推荐
- Python学习笔记之—— File(文件) 对象常用函数
- python 学习笔记(3) 各种数据类型常用的函数
- python学习笔记17-常用函数总结整理
- python学习笔记(三):常用函数和运算优先级
- Python学习笔记(二):条件控制语句与循环语句及常用函数的用法
- Python学习笔记(4)——常用函数
- Python学习笔记 —— 字符串及常用函数
- Python学习笔记——一些常用函数、常见错误总结
- Python学习笔记之常用函数及说明
- python学习笔记——常用类库和函数——日期时间
- Python学习笔记之常用函数及说明
- PL/SQL学习笔记[3]-常用函数
- R语言学习笔记2——常用数学函数
- 【OpenCV学习笔记6】常用的OpenCV函数速查
- php学习笔记------[数组的常用函数]
- Python2.7 学习笔记 (二)—— 函数,模块,正则
- python_模块与函数学习笔记
- php学习笔记 数组的常用函数
- PHP学习笔记(六)四个常用函数
- php学习笔记 数组的常用函数