team1 = [‘a‘,‘b‘,‘c‘]
team2 = [‘x‘,‘y‘,‘z‘] #a 不和x对战,b 不和y,z 对战
# for i in team1: #法一
# for j in team2:
# if i == ‘a‘ and j == ‘x‘:
# continue
# elif i == ‘c‘ and (j == ‘y‘ or j ==‘z‘):
# continue
# else:
# print(‘%s VS %s‘%(i,j))
for t1 in team1: #法二
if t1 == ‘a‘:
tmp = team2[team2.index(‘x‘)+1:] #返回x 的索引
elif t1 == ‘b‘:
tmp = team2[:team2.index(‘y‘)] #返回 y 的索引
else:
tmp = team2
for t2 in tmp:
print(‘%s VS %s‘%(t1,t2))
def func(x):
if x > 0 :
func(x-1)
print(x)
func(5)
输出结果: 1 2 3 4 5 (递归)
循环删list元素
li = [1,1,2,3,4,5,6,7,8,9]
for i in li:
if i%2!=0:
li.remove(i)
print(li)
输出结果: [1, 2, 4, 6, 8]