列表生成式的使用
輸入:['Hello', 'World', 18, 'Apple', None]
輸出:['hello', 'world', 'apple']
L = ['Hello', 'World', 18, 'Apple', None] print([w.lower() for w in L if isinstance(w, str)]) # -- coding: utf-8 -- L = ['Hello', 'World', 18, 'Apple', None] L2 = [] L2 = [w.lower() for w in L if isinstance(w, str)] print(L2) L = ['Hello', 'World', 18, 'Apple', None] i = 0 L2 = [] while i < len(L):if isinstance(L[i], str) and i < len(L):L2.append(L[i])i = i + 1 print(L2)轉(zhuǎn)載于:https://www.cnblogs.com/Tristan-Adams/p/9951591.html
總結(jié)
- 上一篇: 阻止中文输入法输入拼音的时候触发inpu
- 下一篇: 面试专题(Mysql及Mongodb)