Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the built-in functions in Python

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "how to use the built-in functions in Python", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use the built-in functions in Python" article.

First of all, let's talk about a little trick. True can be seen as 1 ~ # false can be seen as 0, and can participate in the operation!

The text begins!

1. Map ()

Map (func,iterable), where func is a function name, can be an lambda anonymous function, and iterable is an iterable object. This function passes each bit element in the iterable object as an argument to the func and adds the func calculation to the new list, and map () returns a new list containing all the results.

2. Filter ()

Filter (func,iterable), where func is a function name, can be an lambda anonymous function, and iterable is an iterable object. This function passes every bit element in the iterable object as an argument to the func, and if the result is True, the element is added to the result list, and the result returned by filter () is a new list.

3. All ()

The (iterable) function is used to determine whether all elements in the given iterable parameter iterable are True, and if so returns True, otherwise it returns False. Iterable can be generated.

All () is often used with filter (), such as the following code to output a number where each digit in 1000-3000 is an even number.

Def check (element): return all (ord (I)% 2 = = 0 for i in element) # all returns True if all digits i is even in element lst = [str (I) for i in range (1000, 3001)] # creates list of all given numbers with string data typelst = filter (check, lst) # filter removes element from list if check condition failsprint ("," .join (lst))

You can also write it this way.

S = [str (n) for n in range (1000Magne3001)] res=filter (lambda n:all (int (I)% 2 for i in n), s) print (', '.join (res)) IV, int ()

1. Int (xQuery y), where x can be a numeric string or a number, and y is a number that represents an integer that converts x to base y

2.int (f), where f is a floating-point number, which is rounded down by default, that is, it is not rounded, but only the integer part is retained.

5. Ord ()

Ord (c), where c is a character and returns the corresponding ASCII code

6. Chr ()

Corresponding to ord (), the chr () parameter is a number of 0,255 and returns the corresponding character.

7. Isalpha ()

The character .isalpha (), which determines whether the character is uppercase or lowercase, and returns True if it is a letter, or False otherwise

8. Isnumeric ()

The character .isnumeric (), which determines whether the character is a numeric character, returns True if it is, or False otherwise

9. Upper ()

Str.upper (), which changes lowercase letters in the string str to uppercase

10. Isupper ()

Str.isupper () returns True; if all letters in str are uppercase, even if they contain other characters. If one letter is lowercase, False is returned.

Islower ()

Str.islower () returns True; if all letters in str are lowercase, even if they contain other characters. If one letter is uppercase, False is returned.

12. Sum ()

Sum (iterable [, n]), where iterable is an iterable object, and the contents in [] represent optional parameters. What this function does is first calculate the sum of the elements in iterable, and then add n to the result of the calculation to get the final result.

Note: iterable objects can only be used once, and the second use will become empty.

The above is about the content of this article on "how to use the built-in functions in Python". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report