Discuss / Python / list中包含非str元素的情况下使str元素都变为小写的方法

list中包含非str元素的情况下使str元素都变为小写的方法

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

  • 1

Reply