06 2022 档案

摘要:import re #findall 匹配所有匹配项,返回一个列表 # ret=re.findall('\d+','hello123,word456') # print(ret) #findall 分组优先原则 显示()的内容 ret=re.findall('\d(\d+)','a12,b34,c5 阅读全文
posted @ 2022-06-30 21:18 爱coding的果妈 阅读(18) 评论(0) 推荐(0) 编辑
摘要:#正则表达式: 只和字符串打交道 # 第一:从一大段文字中获取符合条件的内容,爬虫 # 第二:检测某个字符串是否完全符合规则,表单的验证 # 字符串 # 匹配所有的数字[0-9] # 匹配所有的小写字母[a-z] # 匹配所有的大写字母[A-Z] # 匹配所有的字母数字[0-9a-zA-Z] # [ 阅读全文
posted @ 2022-06-30 20:41 爱coding的果妈 阅读(18) 评论(0) 推荐(0) 编辑
摘要:#模块导入 遵循PEP8规范,一般单行导入 # from day9.aaa import a,b,func from 绝对路径.文件 import 变量 # print(a) # print(b) # print(func()) # from day9.aaa import a as A,b as 阅读全文
posted @ 2022-06-30 20:40 爱coding的果妈 阅读(11) 评论(0) 推荐(0) 编辑
摘要:# 异常捕获 try/except 语句 finally # lst=[1,2,3,4] # try: # num=int(input('>>>>')) # print(lst[num]) # except ValueError: # print('请输入一个数字') # except ValueE 阅读全文
posted @ 2022-06-30 10:04 爱coding的果妈 阅读(27) 评论(0) 推荐(0) 编辑
摘要:import os #文件和文件夹相关 # os.remove() #删除 # os.rename() #重命名 # os.mkdir('dir') #新建文件夹,已存在就报错 # os.makedirs('dir1/dir2') #递归创建多层文件夹,已存在就报错 # os.rmdir('dir' 阅读全文
posted @ 2022-06-30 10:03 爱coding的果妈 阅读(6) 评论(0) 推荐(0) 编辑
摘要:import hashlib #加密的密码不可逆,解不了码 #md5 算法 # md5=hashlib.md5() # md5.update(b'123456') #b 表示字节 # ret=md5.hexdigest() # print(ret) #32位的加密字符串 e10adc3949ba59 阅读全文
posted @ 2022-06-30 10:02 爱coding的果妈 阅读(19) 评论(0) 推荐(0) 编辑
摘要:# globals() 和 locals() # name='xxx' # def func(): # a=1 # print(globals()) # 全局的变量 # print(locals()) #局部的变量 # func() #eval() 函数 用来执行一个字符串的表达式,并返回表达式的值 阅读全文
posted @ 2022-06-30 10:00 爱coding的果妈 阅读(24) 评论(0) 推荐(0) 编辑
摘要:import random # ret=random.random() #(0,1)之间的随机数 # ret1=random.randint(1,3) #随机整数 [1,3]闭区间 # random.randrange(1,12) #随机数[1,12) # random.randrange(1,12 阅读全文
posted @ 2022-06-28 20:52 爱coding的果妈 阅读(7) 评论(0) 推荐(0) 编辑
摘要:三元运算符 返回值 if 条件 else 返回值 #比较2个数大小: #1.以前的方法 # a=10 # b=5 # max=0 # if a>b: # max=a # else: # max=b # print(max) 2.使用三元运算符 a=10 b=5 max=a if a>b else b 阅读全文
posted @ 2022-06-28 20:50 爱coding的果妈 阅读(44) 评论(0) 推荐(0) 编辑
摘要:#列表推导式最大的特点:在一行内完成一个新列表的组件[返回值 for 循环 if条件] #把列表中的元素翻倍 # lst=[1,2,3,4,5] # lst1=[i*2 for i in lst] # print(lst1) #练习 # 1.100以内,能被3整除的数 # lst=[i for i 阅读全文
posted @ 2022-06-28 20:39 爱coding的果妈 阅读(57) 评论(0) 推荐(0) 编辑
摘要:#迭代器的特点: # 1.一个个取值,不是一次性把所有数据都创建出来 # 2.只能按照顺序取,不能回头 # 3.迭代器中的数据,不取不创建 # 4.迭代器中的数据只能从头到尾取一次#可迭代协议:如果一个数据中有iter方法,那么这个数据是一个可迭代的类型#迭代器协议:如果一个数据中有iter方法和n 阅读全文
posted @ 2022-06-28 20:29 爱coding的果妈 阅读(21) 评论(0) 推荐(0) 编辑
摘要:#递归函数:自己调自己 # def xxx(): # a=1 # b=1 # print('xxx') # xxx() # # xxx() #超过了最大的递归深度,官方给的最大深度是1000次 #设置递归深度 from sys import setrecursionlimit # setrecurs 阅读全文
posted @ 2022-06-28 20:11 爱coding的果妈 阅读(37) 评论(0) 推荐(0) 编辑
摘要:装饰器的底层原理:装饰器用到了函数名的本质和闭包; 函数名本质:函数名可以做参数,也可以做返回值 import time #不改变使用者调用方式的情况下,能够添加上这个计算时间功能 def timer(func_name): def inner(): start=time.time() print( 阅读全文
posted @ 2022-06-27 17:38 爱coding的果妈 阅读(36) 评论(0) 推荐(0) 编辑
摘要:import time # def func(): # sum_num=0 # for i in range(1000000): # sum_num+=i # # # start=time.time() # func() # print(time.time()-start) #函数的执行时间 # d 阅读全文
posted @ 2022-06-27 17:32 爱coding的果妈 阅读(11) 评论(0) 推荐(0) 编辑
摘要:什么叫模块: 别人写好的一些功能,放在一个模块里,你可以直接拿来用import time和时间相关的功能,就放在我的time里模块的分类: 内置模块:不需要安装,直接可以使用 扩展模块/第三方模块:需要安装一下 自定义模块:我们自己写的代码 # print(time.time()) #时间戳 #这个 阅读全文
posted @ 2022-06-27 17:15 爱coding的果妈 阅读(56) 评论(0) 推荐(0) 编辑
摘要:按照位置传参 # def func(a,b): # print(a) # print(b) # # func(1,2) # func(2,1) 按照关键字传参 # def func(a,b,c): # print(a) # print(b) # print(c) # # func(a=1,b=2,c 阅读全文
posted @ 2022-06-26 21:00 爱coding的果妈 阅读(14) 评论(0) 推荐(0) 编辑
摘要:形参:先位置,再关键字 # def student(name,score,gender='boy'): #形参 # print('南京三班学生%s,性别%s,成绩%s'%(name,gender,score)) # # student('班长',100) #默认boy,不一样时单独写出来 # stu 阅读全文
posted @ 2022-06-26 20:57 爱coding的果妈 阅读(21) 评论(0) 推荐(0) 编辑
摘要:总结: 永远是局部命名空间可以调用全局的变量,全局命名空间可以调用内置命名空间的变量 但是内置不能调用全局的,全局不能调用局部的 a=1 b=2 # def func(): # name='剑圣' # print(a) # print(b) # print('name ',name) # func( 阅读全文
posted @ 2022-06-26 20:32 爱coding的果妈 阅读(42) 评论(0) 推荐(0) 编辑
摘要:def func(): print(123) return True def func2(): print('start') ret=func() print('ret:',ret) print('stop') return ret ret2=func2() print(ret2) #函数修改全局变 阅读全文
posted @ 2022-06-26 20:27 爱coding的果妈 阅读(19) 评论(0) 推荐(0) 编辑
摘要:函数的作用1.增强代码的可读性2.降低代码的重复性 # def 函数的名字(): # 函数体,也叫代码块 # # def func():#函数的声明 # print(123) # func()#函数调用 lst=[1,2,3,4] # print(len(lst)) #自定义一个查看长度的函数 # 阅读全文
posted @ 2022-06-26 20:13 爱coding的果妈 阅读(15) 评论(0) 推荐(0) 编辑
摘要:#参数 # def len_func(s): #形参 # count=0 # for i in s: # count+=1 # return count # # str1=input('>>>') # str2=input('>>>') # ret1=len_func(str1) #实参 # ret 阅读全文
posted @ 2022-06-26 19:58 爱coding的果妈 阅读(175) 评论(0) 推荐(0) 编辑
摘要:#绝对路径:从磁盘根目录开始一直到文件名#相对路径:读取同一个文件夹下的文件,./文件名 ../返回上一层 #文件的读 #1、相对路径打开 f=open('userinfo') print(f.read()) f=open('./userinfo') #2、绝对路径打开 #在路径前+r #f=ope 阅读全文
posted @ 2022-06-26 19:57 爱coding的果妈 阅读(22) 评论(0) 推荐(0) 编辑
摘要:冒泡排序基本思想:列表每相邻的两个数,如果前面的比后面的大,则交换这两个数目的:排除一个升序的列表一趟排序完后,无序区会减少一个数,有序区会增加一个数外层循环 确定走多少趟 列表长度-1内层循环 比较的次数 列表长度-1-当前第几趟 # lst=[0,34,-3,12,-5,66,333,2] # 阅读全文
posted @ 2022-06-24 21:45 爱coding的果妈 阅读(22) 评论(0) 推荐(0) 编辑
摘要:字典 dict字典的特性就是查询快键值对 key value 字典的key是不可变的,value是可变的 dic={'key':'value',11:'12',True:[1,2],(1,):'你好',2.5:666,'22':{}} # print(dic) 字典的增加 1 dic1={'12': 阅读全文
posted @ 2022-06-24 21:43 爱coding的果妈 阅读(5) 评论(0) 推荐(0) 编辑
摘要:定义:set集合是可变的无序序列,可添加、移除数据,没有索引,不能使用索引和切片集合的特性:1.集合中的对象具有唯一性 (去重)2.无序1、创建set集合 1 #set1={} #方法1 2 # print(type(set1)) 3 # 4 # set2=set() #方法2 5 # 6 # st 阅读全文
posted @ 2022-06-23 21:48 爱coding的果妈 阅读(38) 评论(0) 推荐(0) 编辑
摘要:1、浅拷贝 1 l=['wind',123,True,['张三',123,'18',[12]],['李四',10086]] 2 l1=l.copy() 3 l2=l[:] 4 5 # print(l) 6 # print(l1) 7 # print(l2) 8 9 # l1.append('你好') 阅读全文
posted @ 2022-06-23 21:29 爱coding的果妈 阅读(15) 评论(0) 推荐(0) 编辑
摘要:1、不可变类型(整型,浮点型,布尔值,字符串,元组) 1 name1='asdfg' 2 name2='asdfg' 3 print(id(name1)) 4 print(id(name2)) 5 #内存地址相同 6 7 print(name1==name2) 8 print(name1 is na 阅读全文
posted @ 2022-06-23 21:13 爱coding的果妈 阅读(26) 评论(0) 推荐(0) 编辑
摘要:1、转大写/小写 1 str1='helloworld' 2 # str.upper()#字符串转大写 3 str2=str1.upper() 4 print(str2) 5 6 str2='HEELO' 7 # str.lower()#转小写 8 print(str2.lower()) 2、判断是 阅读全文
posted @ 2022-06-23 21:08 爱coding的果妈 阅读(133) 评论(0) 推荐(0) 编辑
摘要:字符串反转 1、while循环 str01 = "hello"i=len(str01)-1 s='' while i>=0: s+=str01[i] i-=1 print(s) 2、字符串切片 str01 = "hello" print(str01[::-1]) 3、列表函数 str01 = "he 阅读全文
posted @ 2022-06-23 20:15 爱coding的果妈 阅读(5) 评论(0) 推荐(0) 编辑
摘要:su 用户名 切换用户 cd 目录路径 切换所在目录 pwd 查看当前所在位置路径 ifconfig 查看linux服务器ip地址 ip addr ping 网址 检查linux服务器是否联网 ls -l 展示当前目录下所有文件/目录的详细信息 第一位d 代表是目录 第一位- 代表是文件 第一位l 阅读全文
posted @ 2022-06-23 15:04 爱coding的果妈 阅读(24) 评论(0) 推荐(0) 编辑
摘要:# 1.创建一个空列表,命名为names,往里面添加Lihua、Rain、Jack、Xiuxiu、Peiqi和Black元素。# names=list()# names.append('Lihua')# names.append('Rain')# names.append('Jack')# name 阅读全文
posted @ 2022-06-22 21:09 爱coding的果妈 阅读(250) 评论(0) 推荐(0) 编辑
摘要:元组tuple 和列表非常相似,唯一区别:元组是不可变的列表元组的初始化 1 # tup1=() 2 # print(tup1,type(tup1)) 3 # 4 # tup2=tuple() 5 # print(tup2,type(tup2)) 6 7 # tup2=(1) #这个不是元组 8 # 阅读全文
posted @ 2022-06-22 21:06 爱coding的果妈 阅读(17) 评论(0) 推荐(0) 编辑
摘要:#列表的初始化 1 # lst=[] #创建一个空列表 2 # lst1=list() #创建一个空列表 3 # print(lst,type(lst)) 4 # print(lst1,type(lst1)) #字符串转列表 把字符串值一个个取出来 1 # str1='hello world' 2 阅读全文
posted @ 2022-06-22 21:06 爱coding的果妈 阅读(96) 评论(0) 推荐(0) 编辑
摘要:#索引 index#索引位从0开始,不能越界,可以正着取,也可以倒着取# str1='helloworld'# print(str1[0])# print(str1[-1]) #-1 取最后一个元素# 遍历字符串str1='helloworld',把值一个个取出来# str1='helloworld 阅读全文
posted @ 2022-06-22 21:05 爱coding的果妈 阅读(31) 评论(0) 推荐(0) 编辑
摘要:#utf-8可变长的编码--节省空间#如果是英文字母 8位 1字节#如果是欧洲文字 16位 2字节#中国文字 24位 3字节s ='你好,朋友's_byte = s.encode( ' utf-8 ' )#unicode -->utf-8#转成16进制的字节print(s_byte)s2=s_byt 阅读全文
posted @ 2022-06-22 21:04 爱coding的果妈 阅读(44) 评论(0) 推荐(0) 编辑
摘要:#赋值运算符 # num+=1 # num-=1 # num*=1 #身份运算符 1 # a=1 2 # b=1 3 # print(a==b) #判断值是否相等 4 # print(a is b) # 判断内存地址是否相同 5 # #id() #查看内存地址 6 # print(id(a)) 7 阅读全文
posted @ 2022-06-22 21:03 爱coding的果妈 阅读(153) 评论(0) 推荐(0) 编辑

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