![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python语法
程冉
这个作者很懒,什么都没留下…
展开
-
正则表达式
compilecompile(pattern, flags=0):函数功能:“Compile a regular expression pattern, returning a pattern object.”其中pattern是一个正则的格式。msg = "南方少哦i佳偶“pattern = re.compile('南方')result = pattern.match(msg) # <re.Match object; span=(0, 2), match='南方'>match原创 2020-05-21 23:27:39 · 134 阅读 · 0 评论 -
python标准库类bin、oct、hex------转二进制、八进制、十六进制
print(bin(2)) # 0b10print(hex(16)) # 0x10print(oct(8)) # 0o10原创 2020-05-21 12:18:33 · 139 阅读 · 0 评论 -
python标准库类ord、chr-----str与unicode码相互转换
print(chr(65)) # A (Unicode码 ----> str)print(ord('A') # 65 (str ---> Unicode码)print(ord('上’)# 199778 (str ---> Unicode码)原创 2020-05-21 11:53:35 · 371 阅读 · 0 评论 -
python标准库类random
random.randrange(start, stop, step):ran = random.randrange(1, 10, 2) # ran = [1, 3, 5, 7, 9]random.randint(start, stop, step)random.randint(1, 10) # 包括10random.choice():list1 = ['桃子', '李子', '香蕉']ran = random.choice(list1) # 随机选择列表的内容random.shuf原创 2020-05-21 11:42:15 · 97 阅读 · 0 评论 -
python函数sorted()
@python中sortedsorted()sorted函数用来对可迭代对象(比如列表)进行排序。sorted(iterable, key=…,reverse=ture/false),比如 :1、对一维列表进行排序(最简单的、不用key函数):a = [1, 5, 2, 9, 4]b = sorted(a)#默认按ASCII排序print(a)[1, 5, 2, 9, 4]...原创 2019-06-02 12:24:52 · 184 阅读 · 0 评论 -
random 与 numpy.random
random1.random.random()#用于生成一个0到1的随机浮点数:0<= n < 1.0 import random a = random.random()print (a) 2.random.uniform(a,b)#用于生成一个指定范围内的随机符点数,两个参数其中一个是上限,一个是下限。如果a > b,则生成的随机数n: a <= n ...原创 2019-09-14 13:33:56 · 92 阅读 · 0 评论 -
enumerate
语法:enumerate为可遍历对象(列表、字符串、元组)添加索引用法:enumerate(sequence, [start=0])例:原创 2019-09-15 11:02:01 · 93 阅读 · 0 评论