Discuss / Python / 对表达式和筛选的理解和作业

对表达式和筛选的理解和作业

Topic source

#1 Created at ... [Delete] [Delete and Lock User]

对表达式和筛选的理解

a=[x*x if x % 2 == 0 else -x for x in range(1, 11)]

print(a)

b=[x for x in range(1, 11) if x % 2 == 0]

print(b)

作业

L1 = ['Hello', 'World', 18, 'Apple', None]

L2 = [x.lower() for x in L1 if isinstance(x,str)]

print(L2)


  • 1

Reply