
python:内置函数
python内置函数
ws_nlp_
这个作者很懒,什么都没留下…
展开
-
python中使用时间戳timestamp
python中的time.time()就是时间戳代码:import timetime_stamp = time.time()print(time_stamp)time_array = time.localtime(time_stamp)other_way_time = time.strftime("%Y-%m-%d %H:%M:%S", time_array)print(other_way_time)结果:1610608539.83105022021-01-14 15:15:39当原创 2021-01-14 15:21:13 · 10791 阅读 · 0 评论 -
python中的排列组合内置函数
product 笛卡尔积 (有放回抽样排列)permutations 排列 (不放回抽样排列)combinations 组合,没有重复 (不放回抽样组合)combinations_with_replacement 组合,有重复 (有放回抽样组合)详细的参见官网。>>> import itertools>>> for i in itertools.product('ABCD', repeat = 2):... print(i)... ('A原创 2020-10-09 10:58:42 · 1417 阅读 · 0 评论 -
python中打开文件
f=open(‘notfound.txt’, ‘r’)原创 2020-07-24 10:09:43 · 212 阅读 · 0 评论 -
python中assert的用法,多使用assert用来报错
assert n != 0, ‘n is zero!’原创 2020-07-24 09:38:32 · 351 阅读 · 0 评论 -
python中的os内置函数
os中有关文件路径常用的方法os.walk(path)拆分当前路径,返回r,ds,fsos.path.exists(path)当前路径是否存在文件os.path.join(r, f)文件名和根目录拼成文件路径原创 2020-06-19 14:16:02 · 224 阅读 · 0 评论 -
python中的random内置函数
random.randiant(a, b)a到b随机整数,a和b都包括random.sample(list, n)从list中sample取出n个不重复的组成一个list原创 2020-06-19 14:12:25 · 2007 阅读 · 0 评论