Discuss / Python / 交个作业

交个作业

Topic source

落落96897

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

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

#第一种方法

temp = [s.lower() for s in L if isinstance(s,str)]

if temp == ['hello', 'world', 'apple']:

    print('测试通过!')

else:

    print('测试失败!')

#第二种方法

K=[]

for t in L:

    if isinstance(t,str):

        K.append(t.lower())

if K == ['hello', 'world', 'apple']:

    print('测试通过!')

else:

    print('测试失败!')


  • 1

Reply