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 python uses the Map () mapping function

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how python uses the Map () mapping function, which is very detailed and has a certain reference value. Friends who are interested must finish it!

Map () mapping function

The map () function is a higher-order function (that is, a function that takes a function as an argument or returns a value as its output). Its general format is map (function, iterables). The map () function takes an iterable object as an argument and returns a map object, which in turn is an iterator. The number of iterating objects should match the number of parameters required by the function.

In the following example, the built-in function pow () requires two parameters. Of course, you can also use custom functions. By the way, when you use the map () function to create a list, you should be able to use list parsers to achieve the same effect.

> numbers = (1,2,4,6) > indices = (2,1,0.5,2) > > # use map () > list (map (pow, numbers, indices)) [1,2,2.0,36] > # list comprehensions > [pow (x, y) for x, y in zip (numbers, indices)] [1,2,2.0,36] above is all the content of this article "how python uses Map () Mapping function". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to 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