This article mainly introduces the usage of map, any, and all functions in python. The example analyzes the usage skills of map, any, and all functions, which has some reference value, for more information about map, any, and all functions in python, see the following example. Share it with you for your reference. The specific analysis is as follows:
I have been paying more attention to python recently. I saw a post in python yesterday asking me how to judge whether the password complies with the specifications in python. There are many loops in the replies, in addition to a Useless Loop, the code is very concise. below is the code:
Def volid (pwd): a = any (map (str. isupper, pwd) B = any (map (str. islower, pwd) c = any (map (str. isdigit, pwd) d = not all (map (str. isalnum, pwd) return all ([a, B, c, d])
Here, the isupper islower isdigit isalnum function is very easy to understand, that is, to judge whether it is in upper case, whether it is in lower case, whether it is a number, whether it is all numbers and letters (in turn, whether there are other symbols ), here, the map function is to execute each element of the subsequent set with the function of the first parameter, and return a bool type set, the any and all functions on the outermost layer are easier to understand. you can use "or" and "and" to understand them. if one of the parameter sets is true, the any function returns true, it is equivalent to "or" all elements. The "all" function returns true only when all the parameter sets are true. otherwise, false is returned, therefore, if the volid function is used to input a string containing uppercase and lowercase letters, numbers, and special characters, abcd is assigned true and returns true. Therefore, this function can determine that the password is complex enough.
Leave a question for yourself. if you only need to satisfy two of the four items, how to write the function is concise. If you are interested, you can try it out.
I hope this article will help you with Python programming.