|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
因为发布了图片、、、、、、、
代码:import random
schools = [[],[],[]]
teachers = ['1','2','3','4','5','6','7','8']
for name in teachers:
num = random.randint(0,2)
schools[num].append(name)
print(schools)
for office in schools:
print('个数{len(office)}')
打印结果是:
[['4', '8'], ['1', '2', '3', '5', '7'], ['6']]
个数{len(office)}
个数{len(office)}
个数{len(office)}
f-string 得在字符串前面加上 f
- import random
- schools = [[],[],[]]
- teachers = ['1','2','3','4','5','6','7','8']
- for name in teachers:
- num = random.randint(0,2)
- schools[num].append(name)
- print(schools)
- for office in schools:
- print(f'个数{len(office)}') # 这里加上 f
复制代码
|
|