摘要:
程序文件ex2_12_2.py 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=' 阅读全文
摘要:
程序文件ex2_11_2.py import string, random, collections #依次加载三个模块 x=string.ascii_letters+string.digits y=''.join([random.choice(x) for i in range(1000)]) c 阅读全文
摘要:
程序文件ex2_11_1.py import string import random x=string.ascii_letters+string.digits y=''.join([random.choice(x) for i in range(1000)]) choice()用于从多个元素中随机 阅读全文
摘要:
程序文件ex2_10.py Dict={'age':18, 'score':[98,97], 'name':'Zhang', 'sex':'male'} for item in Dict: #遍历输出字典的“键” print(item) print(" " ) for item in Dict.it 阅读全文
摘要:
程序文件ex2_8.py dict1 ={'Alice': '123', 'Beth': '456', 'Cecil': 'abc'} print(dict1['Alice']) #输出123 dict1['new'] = 'Hello' #增加新的键值对 dict1['Alice'] = '123 阅读全文
摘要:
程序文件ex2_7.py student = {'Tom', 'Jim', 'Mary', 'Tom', 'Jack', 'Rose'} print(student) a = set('abcdabc') print(a) #每次输出是不一样的,如输出:{'d', 'b', 'a', 'c'} 阅读全文
摘要:
程序文件ex2_6.py T = ('abc', 12, 3.45, 'Python', 2.789) print(T) #输出完整元组 print(T[-1]) #输出元组的最后一个元素 print(T[1:3]) #输出元组的第二、三元素 阅读全文
摘要:
程序文件ex2_5_2.py from numpy.random import randint import numpy as np a=randint(10,20,16) #生成16个[10,20)上的随机整数 ma=max(a) ind1=[index for index,value in en 阅读全文
摘要:
程序文件ex2_5_1.py import os fn=[filename for filename in os.listdir('D:\Programs\Python\Python37') if filename.endswith(('.exe','.py'))] print(fn) 阅读全文
摘要:
程序文件ex2_4.py a=[[1,2,3],[4,5,6],[7,8,9]] d=[c for b in a for c in b] print(d) 阅读全文