Python isinstance, isalnum function usage

Source: Internet
Author: User

Write a check today, encountered three functions, write down to use it

Isinstance, Isalnum, Len


The data type of an object is judged by the type () function compared to everyone else:

In [1]: test = "abc123" in [2]: Type (test) out[2]: Strin [3]: test = 123In [4]: Type (test) out[4]: int


Next introduce the Isinstance data type, which is used to determine whether a known data type, and the type function is to determine the unknown data type, or the code bar:

In [5]: test = "abc123" in [6]: Isinstance (test,int) out[6]: Falsein [7]: Isinstance (Test, (int,list)) out[7]: False


The basic syntax is isinstance (object, data type/(multiple data types))

Returns true if the data type of the object is contained in the subsequent data type, otherwise false

In [8]: isinstance (Test, (INT,LIST,STR)) out[8]: Truein [9]: Isinstance (TEST,STR) out[9]: True



Well, the next isalnum function, judging whether the string is composed of numbers and letters, continue to

In [ten]: test = "abc123" in [All]: Test.isalnum () out[11]: Truein []: test = "ABC 123" in []: Test.isalnum () out[13]: False in [+]: test = "a" in [All]: Test.isalnum () out[15]: Truein [[+]: Test = "" in []: Test.isalnum () out[17]: False




This article is from the "next door Lao Zhang" blog, please be sure to keep this source http://xxuer.blog.51cto.com/11947593/1931076

Python isinstance, isalnum function usage

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.