a='aaaa'
print isinstance(a, basestring)#true
print isinstance(a, str)#true
a=’aaaa’ print isinstance(a, basestring)#true print isinstance(a, str)#true
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Python versions prior to 3.0 there are two kinds of strings “plain strings” and “unicode strings”. Plain strings (
str) cannot represent characters outside of the Latin alphabet (ignoring details of code pages for simplicity). Unicode strings (unicode) can represent characters from any alphabet including some fictional ones like Klingon.So why have two kinds of strings, would it not be better to just have Unicode since that would cover all the cases? Well it is better to have only Unicode but Python was created before Unicode was the preferred method for representing strings. It takes time to transition the string type in a language with many users, in Python 3.0 it is finally the case that all strings are Unicode.
The inheritance hierarchy of Python strings pre-3.0 is:
‘basestring’ introduced in Python 2.3 can be thought of as a step in the direction of string unification as it can be used to check whether an object is an instance of
strorunicode