Python 列表循环与判断:分离字符串和数字
L = [1, 2, '', 'my', 3, 'name', 'is', 4, 'katty']
# 输出字符串
for item in L:
if isinstance(item, str) and item != '':
print(item)
# 输出数字
for item in L:
if isinstance(item, int):
print(item)
输出结果如下:
my
name
is
1
2
3
4
原文地址: https://www.cveoy.top/t/topic/n5rN 著作权归作者所有。请勿转载和采集!