A big summary of Python3 derivation

Source: Internet
Author: User

Derivation--summing-up and derivation of generators

# #列表推导式

 for inch if  not  and # #注意列表是中括号 Three contents variable cyclic body judging condition # The output is a number that can be divisible by 2 within 100 of the result that matches the judging condition. [2, 4, 8, 10, 14, 16, 20, 22, 26, 28, 32, 34, 38, 40, 44, 46, 50, 52, 56, 58, 62, 64, 68, 70, 74, 76, 80, 82, 86, 88, 92, 94, 98]>>>

# #字典推导式

 for inch # #字典推导式注意 that unique colon ': ' Three items content variable condition loop body # #和列表推导式不一样的就是输出的结果, if the condition is determined the output is true otherwise the output is False {0:true, 1:false, 2:true, 3:false, 4:true, 5:false, 6:true, 7:false, 8:true, 9:false, 10:true, 11:false, 12:t Rue, 13:false, 14:true, 15:false, 16:true, 17:false, 18:true, from: False}>>>

# #集合推导式

 for inch #  ##输出内容 The non-repeating output for the list in this example {1, 2, 3, 4, 5, 6, 7, 9, zero, and}

The "set" is a sequence of unordered, non-repeating elements.
Its main function is as follows:
Go to the weight, turn a list into a set, and then automatically go heavy.
Relationship test, test the intersection of two sets of data, difference set, and the relationship between the set
Set is similar to Dict and is a set of keys, but does not store value. Because key cannot be duplicated, there is no duplicate key in set
You can create a collection using the curly braces {} or the set () function, note: Creating an empty collection must be set () instead of {}, because {} is used to create an empty dictionary. "--------This sentence summed up from the Netizen @ struggle of salted fish

# # #字符串推导式 Look at it.

" i-I in ' I love you! ' ">>> D"i for i in ' I love you! ' " # #我 * Sure enough, we saw that the string in the double brackets was printed out by the original and did not do any work with the other derivations >>>

# # # #那么还有什么可以玩一下推导式那, is there a tuple derivation not played, okay, turn her cards down.

>>> E = (i forIinchRange (10))## #元组使用小括号括起来的>>>e<generator Object <genexpr> at 0x00000000034305e8>## #哎 What's going on, the output is a little different ah, the first word seems to be called the generator, right, this is the derivation of the generator, here is to draw this guy's>>> Next (E)##是生成器就可以使用next () This function class looks at the0>>>Next (E)1>>>Next (E)2>>>Next (E)3>>> forIinchE:#One of the outputs on the top of the #想了一下 is too slow. Come on, let's get the rest of the stuff out .Print(i)456789>>>

#至此我们看到了原来元组是没有推导式的, his writing format is the derivation of the generator, OK, write it down! Tuple original and generator also have such a personal friendship Ah!

# #还有一句话要说, here we find the derivation of the generator, then the generator has a more nasty operation, that is, the generator derivation if as a function of the argument, he can directly write the derivation without having to take their own parentheses (the clothes pulled out of the hey) look like the below

 for  in range (+ )))

# #这个操作就是上边的对比了, remove the parentheses (I'll keep you)

Thank you: Little Turtle

A big summary of Python3 derivation

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.