Python basestring ()

Source: Internet
Author: User

Role:

Basestring is a superclass (parent class) of STR and Unicode, and therefore cannot be invoked and instantiated, but can be used to determine whether an object is an instance of STR or Unicode, isinstance (obj, basestring) Equivalent to Isinstance (obj, (str, Unicode));

Note:

This function is introduced after the python2.3 version, compatible with python2.3 later python2 versions. Note: This function is discarded in python3, so the function cannot be used in Python3.

Instance:

1>>> Isinstance ("Hello World", str)2 True3>>> Isinstance ("Hello World", basestring)4 True5>>> isinstance (U"Hello", Unicode)6 True7>>> isinstance (U"Hello", basestring)8True

A quick and easy way to check whether an object is a string or Unicode object is to use the built-in isinstance and basestring, as follows:

1 def isastring (anobj): 2    return isinstance (anobj, basestring)

Python basestring ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.