- 博客(24)
- 问答 (1)
- 收藏
- 关注
原创 验证素数的函数
更加简便的方法def zs(self):for i in range(2,int(self**0.5+1)):if self % i == 0:breakelse:return 1n = int(input())for x in range(2,n):if zs(x) and zs(n-x):#这里的n-x处理很简便print(’{} = {} + {}’.format(n,x,n-x))break
2020-09-04 12:56:59 98
原创 集合和字典的一些小知识点
1.集合的元素类型要是固定的int float string tuple不可以是列表 dict set2.dict的键也要固定不可以是列表 dict3.dict的keys不可以重复
2020-05-15 16:53:14 150 1
原创 continue和break
continue跳过下面的语句从while true开始判断还要不要继续执行break直接跳出整个循环循环里所有语句不执行跳过整个而不是一轮
2020-05-14 18:18:15 80
原创 #format的格式化输出
print(’{0:$>10}’.format(55))$$$$$$$$55#format用<>^分别表示左居中右居中和居中0是代表第一个位置#:s字符串输出#:d十进制输出print(’{0:b}’.format(10))1010#:b二进制print(’{0:o}’.format(10))12#:o八进制print(’{...
2020-03-26 20:09:31 324
原创 #列表的冒号#列表元素倒序排列
a = [2,3,4,5,2,8,6,4]a[::2][2, 4, 2, 6]a[2::2][4, 2, 6]#列表[开始的下标:结束的下表:步长]
2020-03-24 20:24:39 115
原创 #sort #shuffle
a = [3,46,2,45,32,45,1]print(a)[1, 2, 3, 32, 45, 45, 46]#将其按小到大排序
2020-03-24 19:37:09 75
原创 #map函数 #split
lst = list(map(int,input().split()))2 3 4453 6#输入print(lst)[2, 3, 4453, 6]#结果#将输入split(分开)再将分开的元素按照int函数转化成实数list函数转成一个列表map就是将后面的序列用前面的函数执行一遍输出记住一个要点split分割字符串以空格为标识分割若无空格不分割a ...
2020-03-24 19:33:48 1027
原创 元组tuple与列表的区别
元组不可被更改元组用()列表用[ ]p =(1,2)p[0]1p[0] = 9Traceback (most recent call last):File “<pyshell#90>”, line 1, in p[0] = 9TypeError: ’tuple’ object does not support item assignment#元组不...
2020-03-06 13:54:40 171
原创 #split #join
t = ‘i love you’t.split()[‘i’, ‘love’, ‘you’]s = t.split()’ '.join(s)‘i love you’‘-’.join(s)‘i-love-you’#这里注意join函数的用法
2020-03-06 13:41:07 88
原创 #reverse 倒转函数 #pop()
t = [1,2,3,4,5]t.reverse()t[5, 4, 3, 2, 1]t.pop()1t[5, 4, 3, 2]t.pop(0)5t[4, 3, 2]
2020-03-06 11:29:58 169
原创 #append #insert #extend #remove
t = [1,2,3,4,5,6,7]t.append(8)t[1, 2, 3, 4, 5, 6, 7, 8]t.extend([9,10])t[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]t.insert(0,0)t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]#下面是一些比较特殊的方式t.append...
2020-03-06 11:25:43 122
原创 列表替换的一些小知识 替换添加元素
t = [1,2,3,4,5]t[1:3] = [10]t[1, 10, 4, 5]t[1:3] =[20,30,40,50,60]t[1, 20, 30, 40, 50, 60, 5]t[1:6] = []t[1, 5]
2020-03-06 10:55:55 389
原创 关于列表矩阵 列表变量的权限
t = [[1,2,3],[4,5,6],[7,8,9]]len(t)3t[0][1, 2, 3]t[0][0]1#相当于一个3X3的矩形t1 = tt1[[1, 2, 3], [4, 5, 6], [7, 8, 9]]t2 = t1t1[0] = 0#这里只改变了t1t1[0, [4, 5, 6], [7, 8, 9]]...
2020-03-06 10:45:59 119
原创 #replace() #strip()
s = ’ hello world ’s.strip()‘hello world’s.rstrip()’ hello world’s.lstrip()'hello world ’s.replace(’ ‘,’’)‘helloworld’#将空格替换成无空格s.replace (’ ‘,’-’)‘-hello-world-’s.replace ...
2020-03-06 10:27:11 100
原创 #find #index 两个查找函数
s = ‘hello world’s.find(‘l’)2s.find(‘l’,3)3s.find(‘l’,4)9find逗号指从第几个数开始查找
2020-03-06 10:15:38 233
原创 python learning notes02 #upper()
#upper()#note02 =‘i love yuri’note02.upper()‘I LOVE YURI’upper的括号虽不填写参数但必须跟上
2020-03-04 19:54:51 123
原创 python learning notes 01 #range
#range#list(range(5))[0, 1, 2, 3, 4]list(range(3,6))[3, 4, 5]list(range(3,6,2))[3, 5]
2020-03-04 19:45:12 96
空空如也
请问电脑的亮度调节消失了有人懂怎么解决吗
2021-09-20
TA创建的收藏夹 TA关注的收藏夹
TA关注的人