
python函数
xiaobai_IT_learn
找到自己的目标,加油!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python计算取整和保留小数
1.int()向下取整 内置函数 1 n = 3.75 2 print(int(n)) >>> 3 2.round() 四舍五入 内置函数 1 n = 3.75 2 print(round(n)) >>> 4 3.floor() 向下取整 math模块函数 1 import math 2 n = 3.75 3 print(math.floor(n)) >...原创 2019-10-18 13:02:06 · 1805 阅读 · 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 = 123456 print(",".join(t1), type(",".join(t1))) p...原创 2019-09-11 16:53:32 · 383 阅读 · 0 评论 -
python逐行读取文件,readline,readlines,for,read
参照:https://blog.youkuaiyun.com/enweitech/article/details/78790888 1.readline,优点:节省内存,不需要一次性把文件内容放入内存中缺点:速度相对较慢 f = open("ip.txt", "r", encoding="utf-8") ret = f.readline() while ret: print(ret, end='') ...原创 2019-09-22 16:34:10 · 8783 阅读 · 0 评论 -
python中hashlib加密变量,md5,sha1
1.hashlib中md5,MD5是最常见的摘要算法,速度很快,生成结果是固定的128 bit字节,通常用一个32位的16进制字符串表示 import hashlib md5 = hashlib.md5() md5.update(b'hello world') # 需要传入字节类型数据 print(md5.hexdigest()) # 5eb63bbbe01eeed093cb22bb8f5a...原创 2019-09-23 22:50:20 · 696 阅读 · 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 · 250 阅读 · 0 评论 -
python中os模块
import os os.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 · 168 阅读 · 0 评论