将列表中的大写字母转换成小写
如果list中既包含字符串,又包含整数,由于非字符串类型没有lower()方法,
L1 = ['Hello', 'World', 18, 'Apple', None]
请修改列表生成式,通过添加if语句保证列表生成式能正确地执行.

# -*- coding: utf-8 -*-

L1 = ['Hello', 'World', 18, 'Apple', None]
L2 = [s.lower() for s in L1 if isinstance(s,str)==True]
# 测试:
print(L2)
if L2 == ['hello', 'world', 'apple']:
    print('测试通过!')
else:
    print('测试失败!')


相关文章:

  • 2022-01-13
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2021-07-31
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2021-04-08
  • 2021-12-03
  • 2021-10-07
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
相关资源
相似解决方案