Why isn’t isnumeric working?

No, str objects do not have an isnumeric method. isnumeric is only available for unicode objects. In other words:

>>> d = unicode('some string', 'utf-8')
>>> d.isnumeric()
False
>>> d = unicode('42', 'utf-8')
>>> d.isnumeric()
True

isnumeric() only works on Unicode strings. To define a string as Unicode you could change your string definitions like so:

In [4]:
        s = u'This is my string'

        isnum = s.isnumeric()

This will now store False.

Note: I also changed your variable name in case you imported the module string.

Leave a Comment