friends , If you need to reprint, please indicate the source ：blog.csdn.net/jiangjunsho…
Statement ： During the teaching of artificial intelligence technology , Many students mentioned to me python Related issues , So in order to let students master more extended knowledge and better understand artificial intelligence technology , I put the assistant in charge of sharing this python Series of tutorials , I hope that helps ！ Because of this python The tutorial is not to be written by , So it's not as funny as my AI teaching , It's boring to learn ; But its knowledge is in place , It's also worth reading ！
List resolution expressions are usually better than for Efficient circulation .
The following is to calculate the square of each number in a list by parsing the expression in the list ：
>>> squares = [x ** 2 for x in [1,2,3,4,5]] >>> squares [1,4,9,16,25] 12345 Copy code
Here is the passage for Loop to do the same thing ：
>>> squares =  >>> for x in [1,2,3,4,5]: # This is what a list comprehension does squares.append（x ** 2） # Both run the iteration protocol internally >>> squares [1,4,9,16,25] 1234567891011 Copy code
It can be seen that , The method of parsing expressions by list is more concise and clear . also , List parsing and related function programming tools , Such as map and filter, It usually works better than for Fast circulation （ Maybe twice as fast ）： This has a significant impact on the processes that deal with big data （ For example, artificial intelligence AI Program ）.