Little Turtle Fifth day p44-64 python

Source: Internet
Author: User

1.% around average digit > remainder% appears in the character, representing the formatting operator

2.python escape character and Meaning:

\ ' single quotation mark \ r carriage return \ ' double quotation mark \f page break \a emits the system ring ringtone \o The octal number represents the character \b Backspace

\x hexadecimal number represents the character \ n line break = a null character \ t transverse tab \ \ backslash \v Portrait tab

3.len (sub) #len方法用于返回sub参数的长度

>>>list=[1,2,3,4]

>>>len (list)

5

--end

2.max (...) #用于返回序列中或参数集合中最大值 must ensure uniform parameter/sequence data types

3.sum (Iterable[,start]) #用于返回数列总和

>>>tuple=1,2,3

>>>sum (tuple)

6

Default 0, if >>>sum (tuple,10)

16

Sorted and sort. The former sub-function does not change, the latter sub-function becomes sort after the

Reversed and reverse. The former returns a flipped iterator object, which changes directly to inverted inversion.

Enumerate

#>>>for each in Enumerate (list):

Print (each)

(0, ' x ')

(1, ' 2 ')

Zip #用于返回各可迭代共同组成的元组

>>>list=[1,2,3]

>>>str= "Myj"

>>>for each in Zip (LIST,STR):

Print (each)

(1. "M") ...

4. Create and Invoke functions:

>>>def myfirstfunction ():

Print ("Hello World")

>>> myfirstfunction ()

Hello World

>>>def First (name):

Print (name+ "is Handsome")

>>>first ("Myj")

Myj is handsome.

5. Collecting parameters

>>>def Test (*parms):

Print ("%d parameters"%len (parms))

Print ("The second parameter is:", parms[1]) # * Pack

>>>def Test (*parms) #* unpacking

>>>a=[1,2,3]

>>>test (*a)

There are three parameters, the second parameter is 2.

6. function variables: A. Local variables cannot be modified and accessed by external functions, and global variables can be modified but useless.

B. The global variable All code is accessible, but do not attempt to change inside the function, because Python automatically creates a local variable with the same name inside the function instead.

      Global #改包, humbly accept, deadly not change

>>>count=5

>>>def myfun ():

count=10 to modify global count run results by inserting global count into a row on count=10 =10

Print (count)

>>>myfun ()

5

7. Inline functions:

>>>def fun1 ():

Print ("...")

Def fun2 ():

Print ("...")

8. Closure #应用于游戏内人物移动. References to external scope (non-global) variables in intrinsic functions

9. Lambda #匿名函数.

>>>g=lambda x:2*x+1 >>>G=LAMBD X,y:x+y

>>>g (5) >>>g (3,4)

11 7

10.filter #写一个筛选奇数的计数器  

>>>list (Filter (Lambda (X:x%2,range (10)))

>>>[1,3,5,7,9]

? mapping map.

List (Map (Lambda (X:x%2,range (10)))

[0,2,4,6,8,10,12,14,16,18]

Little Turtle Fifth day p44-64 python

Related Article

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.