python函数
xiaobai_IT_learn
找到自己的目标,加油!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python计算取整和保留小数
1.int()向下取整 内置函数1 n = 3.752 print(int(n))>>> 32.round() 四舍五入 内置函数1 n = 3.752 print(round(n))>>> 43.floor() 向下取整 math模块函数1 import math2 n = 3.753 print(math.floor(n))>...原创 2019-10-18 13:02:06 · 1847 阅读 · 0 评论 -
python中join,split,strip,eval,getattr,字典的值为列表,判断两个列表包含关系,python判断变量是否为int,str,list,tuple,dict
1.join(),可以对str、lsit、tuple、dict用,但是不能对int,str.join(sequence)t1 = ("a", "b", "c")s1 = "abc"l1 = ["a", "b", "c"]d1 = {"a": 1, "b": 2, "c": 3}n1 = 123456print(",".join(t1), type(",".join(t1)))p...原创 2019-09-11 16:53:32 · 407 阅读 · 0 评论 -
python逐行读取文件,readline,readlines,for,read
参照:https://blog.youkuaiyun.com/enweitech/article/details/787908881.readline,优点:节省内存,不需要一次性把文件内容放入内存中缺点:速度相对较慢f = open("ip.txt", "r", encoding="utf-8")ret = f.readline()while ret: print(ret, end='')...原创 2019-09-22 16:34:10 · 8819 阅读 · 0 评论 -
python中hashlib加密变量,md5,sha1
1.hashlib中md5,MD5是最常见的摘要算法,速度很快,生成结果是固定的128 bit字节,通常用一个32位的16进制字符串表示import hashlibmd5 = hashlib.md5()md5.update(b'hello world') # 需要传入字节类型数据print(md5.hexdigest()) # 5eb63bbbe01eeed093cb22bb8f5a...原创 2019-09-23 22:50:20 · 718 阅读 · 0 评论 -
python匿名函数lambda、map、filter、zip
1.匿名函数lambda x: x * x等价于def f(x): return x * x①冒号:前面的是函数的变量,后面的时候函数体②匿名函数有个限制,就是只能有一个表达式,不用写return,返回值就是该表达式的结果2.map(function, iterable, …),会根据提供的函数对指定序列做映射map(lambda x: x**2, [1, 2, 3, 4,...原创 2019-09-23 23:18:11 · 267 阅读 · 0 评论 -
python中os模块
import osos.path.abspath(__file__) # 获取当前文件的路径os.path.dirname(path) # path路径的上一级os.path.exists(path) # 文件或者文件夹是否存在,bool类型os.mkdir(path) # 创建文件夹os.path.join(path1, path2) # 将多个路径组合返回列子1:创建目...原创 2019-09-23 23:59:53 · 184 阅读 · 0 评论
分享