This Code cannot use lambda.

Source: Internet
Author: User
Code 1 Import Math
2
3 Def Getallprime (maxnum ):
4 If Maxnum < 10000 :
5 Return [Num For Num In Range ( 2 , Maxnum) If 0 Not   In [Num % I For I In Range ( 2 , INT (math. SQRT (Num )) + 1 )]
6 Else :
7 Return [Num For Num In Xrange ( 2 , Maxnum) If 0 Not   In [Num % I For I In Range ( 2 , INT (math. SQRT (Num )) + 1 )]
8
9 If   _ Name __ = ' _ Main __ ' :
10 Def Print (s ):
11 Print S
12 [Print (I) For I In Getallprime ( 100 )] # Right
13 # [(Lambda X: Print X) (I) for I in getallprime (10)] # error

Cause:

Lambda statements are used to create function objects. Essentially, Lambda requires a parameter, followed by a single expression as the function body, and the value of the expression is returned by the newly created function. Note that even print statements cannot be used in the lambda format, but expressions are only allowed.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.