摘要:
f = lambda x,y,z:x * y * z L = lambda x :[x**2,x**3,x**4] print(f(3,4,5));print(L(2)) print("学号:3008") 结果如下图 阅读全文
posted @ 2024-10-15 17:08
方~~
阅读(10)
评论(0)
推荐(0)
摘要:
def bifurcate_by(L,fn): return [[x for x in L if fn(x)], [x for x in L if not fn(x)]] s = bifurcate_by(['beep','boop','foo','bar'],lambda x: x[0] == ' 阅读全文
posted @ 2024-10-15 17:06
方~~
阅读(7)
评论(0)
推荐(0)
摘要:
#定义阶乘函数 def factorial(n): r = 1 while n > 1: r *= n n -= 1 return r def fib(n): a,b = 1,1 while a < n: print(a,end=' ') a,b = b,a+b print('%d! = %d'%( 阅读全文
posted @ 2024-10-15 17:04
方~~
阅读(21)
评论(0)
推荐(0)
摘要:
import stringimport randomx=string.ascii_letters+string.digitsy=".join([random.choice(x)for i in range(1000)])" #choice()用于从多个元素中随机选择一个d= dict()for ch 阅读全文
posted @ 2024-10-15 17:02
方~~
阅读(39)
评论(0)
推荐(0)
摘要:
#利用collections模块的Counter()函数直接作出统计 #依次加载三个模块 import string,random,collections x = string.ascii_letters + string.digits y = ''.join([random.choice(x) f 阅读全文
posted @ 2024-10-15 16:51
方~~
阅读(83)
评论(0)
推荐(0)
摘要:
'''可以对字典对象进行迭代或者遍历,默认是遍历字典的键,如果需要遍历 字典的元素必须使用字典对象的items()方法明确说明,如果需要遍历字典的 值则必须使用字典对象的values()方法明确说明 ''' Dict = {'age':18,'name':'Zheng','sex':'male'} 阅读全文
posted @ 2024-10-15 16:46
方~~
阅读(12)
评论(0)
推荐(0)
摘要:
'''字典对象提供了一个get()方法用来返回指定键对应的值,并且允许指定键不存在时返回特定的值''' Dict = {'age':18,'sorce':'Zheng','sex':'male'} #输出键对应的值 print(Dict['age']) print(Dict['sorce']) pr 阅读全文
posted @ 2024-10-15 16:44
方~~
阅读(54)
评论(0)
推荐(0)
摘要:
'''字典用{}标识,它是一个无序的“键(key):值(value)”对集合。 在同一个字典中,键必须是唯一的,但值不必唯一,值可以是任何数据类型, 但键必须是不可变的,如字符串,数字,元组''' #首先需要先定义一个字典 dict1 = {'Alice':'123','Beth':'456','C 阅读全文
posted @ 2024-10-15 16:43
方~~
阅读(11)
评论(0)
推荐(0)
摘要:
'''集合是一个无序不重复元素的序列,有两种表示方法:1.使用{}2.使用set()函数,使用空集合必须使用set()''' #首先先定义一个集合student ={'Tom','Jim','Mary','Tom','Jack','Rose'} #输出集合studentprint(student) 阅读全文
posted @ 2024-10-15 16:42
方~~
阅读(23)
评论(0)
推荐(0)
摘要:
T = ('abc',12,3.45,'python',2.789)#输出完整数组print(T)#输出元组的最后一个元素print(T[-1])#输出元组的第二、三元素print(T[1:3])print("学号:3008") T = ('abc',12,3.45,'python',2.789) 阅读全文
posted @ 2024-10-15 16:40
方~~
阅读(18)
评论(0)
推荐(0)