I have a list containing strings. These strings are either words or integer values. For example this list might look like this:
['0', 'Negate', '-3', '2', 'SPECIALCASE', '3']
Now, based on their type (integer or string), I want to treat them differently. However, as you have noticed I can't use isinstace()
. I can still use type()
and try to convert the integer values using the int()
function and put the whole thing in a try-except method to avoid raising errors for the conversion of words. But this seems hackish to me. Do you know the right way of handling this case? Thanks in advance!
'-3'
to be handled? should that be anint
? what if you have2.45
should that be a string or a number? should it be converted to afloat
or anint
? probably your best shot should be try/except unless you want to go into bitwise checks.