a=[1, 2, 3, -2, -5, -6, 'geo']
for I in a:
if I == star:
continue
if I<0:
print('I=', I) 请帮帮我。
发布于 2018-02-01 20:23:16
我想这就是你要找的东西。我修复了几个格式问题。
a = [1, 2, 3, -2, -5, -6, 'geo']
for I in a:
if I == 'star':
continue
try:
if I < 0:
print('I=', I)
except TypeError:
continue
# I= -2
# I= -5
# I= -6已更新以仅捕获TypeError以外的错误。
发布于 2018-02-01 20:24:52
据我所知,您只想打印负整数。
下面的代码可以做到这一点:
a=[1, 2, 3, -2, -5, -6, 'geo']
for I in a:
if type(I) is int:
if I < 0:
print('I=', I)输出:
I= -2
I= -5
I= -6
发布于 2018-02-01 20:23:04
isinstance是最好的选择。
if isinstance(l, int) and l < 0:
print('l=', l)https://stackoverflow.com/questions/48562563
复制相似问题