Unicode string appears as false in isinstance()

Asked 2 years ago, Updated 2 years ago, 90 views

As far as I know, the integer value should be checked with isinstance(x, int);.

However, when I wrote isinstance(x,str);, Unicode is not recognized as a string, so I can't do anything.

What should I do?

>>> foo = u"hello"
>>> isinstance(foo, str)
False
>>> 

string python type variable

2022-09-22 13:10

1 Answers

You must be using the Python 2.x version. In python2,

isinstance(s, basestring)

You have to write it like this.

If you search it and write it down for those who come in,

In Python3, there is no basering

isinstance(s,str);

You can use it as


2022-09-22 13:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.