Discuss / Python / 打卡

打卡

Topic source

余吟21607

#1 Created at ... [Delete] [Delete and Lock User]
L2 = [m.lower() for m in L1 if isinstance(m, str)]  # 不输出字符串以外的
L2 = [m.lower() if isinstance(m, str) else m for m in L1]   # 这样不行么,数字以及其他类型不进行转换

落落96897

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

if 放在前面是表达式,if else一定会有一个结果  ,else m其实已经在进行转换进行输出了,所以会报错


  • 1

Reply