今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
What are comprehensions?
- [Narrator] In this chapter, we'll learn about a Python language construct known as comprehensions. These can be applied to lists, sets, and dictionaries. Now, to understand what these are, think back to earlier in the course when we used the map function to derive a new list of values from an existing list of values. And recall that the map function takes a function as a parameter, which is then applied to each member of a list of values. And then, we wrapped that call in a list function to create a new list of values. Now in our example, we converted temperatures from one scale to another using this kind of approach. It turns out that this kind of operation is a fairly common thing to do in Python programs. So common, in fact, that the language itself has a special syntax for performing these kinds of operations. I can achieve the same result as this complex line of code by writing the following. First, I write the expression that I want to apply to the values, and this is…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。