随笔分类 -  python函数

摘要:any(iterable): return any(filename.endswith(extension) for extension in [".png", ".jpg", ".jpeg"]) all(iterable) 阅读全文
posted @ 2020-10-31 19:35 6+0 阅读(93) 评论(0) 推荐(0)
摘要:a = 'acd'b = 'bd'c = 'abc'print(b > a)print(a < c)TrueFalse 阅读全文
posted @ 2020-09-30 21:15 6+0 阅读(69) 评论(0) 推荐(0)
摘要:将元组或者字符串转化为列表 a = 'str'print([a])print(list(a))print(list(['str', 2, 3])) ['str']['s', 't', 'r']['str', 2, 3] 阅读全文
posted @ 2020-09-17 19:41 6+0 阅读(91) 评论(0) 推荐(0)
摘要:a = [1, 2, 3]b = 'abc'print(a * 2)print([a] * 3)print(b * 3)print([b] * 3)print([[a]] * 3) [1, 2, 3, 1, 2, 3][[1, 2, 3], [1, 2, 3], [1, 2, 3]]abcabcab 阅读全文
posted @ 2020-09-15 10:48 6+0 阅读(140) 评论(0) 推荐(0)
摘要:vars(object) 将一个对象的属性和值组成一个字典 阅读全文
posted @ 2020-08-25 16:41 6+0 阅读(281) 评论(0) 推荐(0)
摘要:获得一个对象的相应的键值 value = getattr(object, key) 阅读全文
posted @ 2020-08-25 16:39 6+0 阅读(134) 评论(0) 推荐(0)
摘要:insert(位置,数值) 阅读全文
posted @ 2020-08-23 21:29 6+0 阅读(171) 评论(0) 推荐(0)
摘要:将数组或字符串反转 阅读全文
posted @ 2020-08-22 21:10 6+0 阅读(102) 评论(0) 推荐(0)
摘要:可以使可迭代对象中重复的元素之保留一个 阅读全文
posted @ 2020-08-05 15:53 6+0 阅读(78) 评论(0) 推荐(0)
摘要:1、del (1)del list[0] 删除一个元素 (2)del list 删除整个列表 2、clear 清空整个列表 以上两种方法可以用列表、字典,不可用于元组 阅读全文
posted @ 2020-08-05 08:31 6+0 阅读(243) 评论(0) 推荐(0)
摘要:1、int 保留整数部分 2、round 四舍五入 3、math.ceil 向上取整 4、math.floor 向下取整 阅读全文
posted @ 2020-08-04 22:18 6+0 阅读(196) 评论(0) 推荐(0)
摘要:1、* (1)接收的参数看作元组来处理 (2)列表、元组等可迭代对象前加*,解释器将自动进行解包传递给多个单变量 2、** (1)接收的参数看作字典来处理 def fun(**kwargs): print(kwargs)def main(): fun(c=2) fun(**{'c': 2}) 阅读全文
posted @ 2020-08-03 23:00 6+0 阅读(114) 评论(0) 推荐(0)
摘要:random.shuffle(list) 将list中的内容打乱 阅读全文
posted @ 2020-08-01 19:48 6+0 阅读(120) 评论(0) 推荐(0)
摘要:将多个可迭代数据中对应位置的元素打包成一个元组,可以用一个循环全部遍历 阅读全文
posted @ 2020-07-24 17:07 6+0 阅读(162) 评论(0) 推荐(0)
摘要:isinstance(obj, type) 判断obj的类型是否为type或者type中的一种 阅读全文
posted @ 2020-07-24 16:52 6+0 阅读(241) 评论(0) 推荐(0)
摘要:过滤掉不符合条件的元素,返回由符合条件的元素组成的列表。 filter(fun, iterable) fun返回的时True和False 阅读全文
posted @ 2020-07-21 16:39 6+0 阅读(121) 评论(0) 推荐(0)
摘要:map(fun, iterable) map(fun(x, y), iterable1, iterable2) 变量送入fun函数中的返回值组成的列表 阅读全文
posted @ 2020-07-21 16:23 6+0 阅读(89) 评论(0) 推荐(0)
摘要:assert len(x.shape) in (2, 4) 阅读全文
posted @ 2020-07-04 20:32 6+0 阅读(202) 评论(0) 推荐(0)
摘要:1、获取URL对应的资源 get、head 2、实例 try: url = 'https://www.baidu.com/s?' kv = {'wd': 'python'} hd = {'user-agent': 'Chrome/10'} r = requests.get(url, params=k 阅读全文
posted @ 2020-06-22 18:13 6+0 阅读(140) 评论(0) 推荐(0)
摘要:将可迭代的对象的对应位置打包成一个元组,若没有对应位置则不打包,返回的是由这些 元组构成的列表。 阅读全文
posted @ 2020-06-08 15:01 6+0 阅读(161) 评论(0) 推荐(0)