a=[1, 2, 3, -2, -5, -6, 'geo']
for I in a:
if I == star:
continue
if I<0:
print('I=', I)
I don't know how to let my program to distill the negative numbers and print only them avoiding strings. Please help me.
a=[1, 2, 3, -2, -5, -6, 'geo']
for I in a:
if I == star:
continue
if I<0:
print('I=', I)
I don't know how to let my program to distill the negative numbers and print only them avoiding strings. Please help me.
This is what I think you are looking for. I fixed several formatting issues.
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
Updated to catch only errors other than TypeError
.
As per my understanding, you want to print only negative integers.
Below code should do it:
a=[1, 2, 3, -2, -5, -6, 'geo']
for I in a:
if type(I) is int:
if I < 0:
print('I=', I)
Output:
I= -2
I= -5
I= -6
isinstance is the way to go.
if isinstance(l, int) and l < 0:
print('l=', l)