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