随笔分类 -  python基础

摘要:open(file, mode='r',encoding="utf-8") t 文本模式 b 二进制模式 f = open(文件名或路径) #打开文件 f.close() #关闭文件 encoding编码 utf-8 是针对Unicode的一种可变长度字符编码 f = open(file="test 阅读全文
posted @ 2024-06-20 22:55 淡然。。 阅读(25) 评论(0) 推荐(0) 编辑
摘要:类的封装 实例化了类后,可以直接访问对象里的属性,也可以去修改对象里的属性 class Student: # 类属性 def init(self, name,score): # 实例属性 self.name = name self.score = score stu= Student('wang', 阅读全文
posted @ 2024-06-11 17:12 淡然。。 阅读(6) 评论(0) 推荐(0) 编辑
摘要:面向对象 class定义类 类和实例 class Student: # 类属性 province = '天津' def init(self,name): # 实例属性 self.name = name # 实例方法 def say(self): print('{}说我今天要唱歌'.format(se 阅读全文
posted @ 2024-06-10 23:06 淡然。。 阅读(6) 评论(0) 推荐(0) 编辑
摘要:reduce #倒序 lists = [2,5,2,4,7] print(sorted(lists,reverse=True)) filter #过滤序列,过滤掉不符合条件的元系 def get_data(x): return x%2==0 #查询1-100的偶数 print(list(filter 阅读全文
posted @ 2024-06-10 22:08 淡然。。 阅读(9) 评论(0) 推荐(0) 编辑
摘要:def hello(username): username = '大西瓜' def world(status): return username+status return world def nihao(username): username='小西瓜' def world(status): re 阅读全文
posted @ 2024-06-10 21:58 淡然。。 阅读(5) 评论(0) 推荐(0) 编辑
摘要:装饰器 在不改变原来函数的基础上,给函数添加新的功能 import time 装饰器 def get_data(func): def get_hello(*args,**kwargs): begin_time = time.time()#开始时间 data = func() #调用函数 stop_t 阅读全文
posted @ 2024-06-06 19:32 淡然。。 阅读(3) 评论(0) 推荐(0) 编辑
摘要:def yang_hui_san_jiao(num): lists = [1,1] yield [1] yield lists for i in range(num-2): kong = [] for ii in range(len(lists)-1): kong+=[lists[ii] + lis 阅读全文
posted @ 2024-06-06 14:43 淡然。。 阅读(10) 评论(0) 推荐(0) 编辑
摘要:可迭代对象 能被for循环遍历的元素 lists = [1,2,3,4] for i in lists: print(i) 生成器是一种特殊的变量 斐波那契数列生成器 def get_data(num): x = 0 y = 1 for i in range(num): x,y = y,x+y yi 阅读全文
posted @ 2024-06-06 14:41 淡然。。 阅读(6) 评论(0) 推荐(0) 编辑
摘要:用def定义一个函数 不定长函数 def hello(*args):#返回是一个集合 print(args) # print(min(args)) # print(max(args)) hello(5,2,1,6,3) def hello(**kwargs):#返回是一个字典 print(kwarg 阅读全文
posted @ 2024-06-06 14:03 淡然。。 阅读(3) 评论(0) 推荐(0) 编辑
摘要:from copy import copy,deepcopy lists = [1,2,3,4,5,[6]] new_lists = copy(lists) # print(new_lists) # lists.append(7) # print(lists,new_lists)#直接修改列表外元素 阅读全文
posted @ 2024-06-06 13:58 淡然。。 阅读(4) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示