Python Learning record-2016-01-19

Source: Internet
Author: User

Today's learning Record:

Functions, variables

Examples of functions:

#函数返回def test1 (): Print ("in the Test1") return 0#return is empty, when not written, this function is a procedure, the default return is empty, that is, none; #return为一个对象时, return this object directly, such as 0, return 0 ; #retrun为很多对象时, such as the three-dimensional and list, dictionaries, etc., will form a tuple to return

#函数变量示例:

#变量def  test1 (x, Y, z)     print     print (y)      print (z) test1 (All-in-one) #其中, with a real argument, x, Y, z as a parameter, and a position variable, each of which corresponds to the Test1 (x=1,y=2,z=3) #其中, the variable is a keyword variable, and the position can be arbitrarily changed, such as Y=1, X=2,z=3test1 (1,2,z=3) #可以这么写, the keyword variable must be located after the position variable test1 (1,y=2,3) #不可以这么写, for reasons such as the # Default variable def test1 (x,y=2,z)      print (x)     print (y)     print (z) test1 (1,3) #其中, x=1,y=2,z= 3,y default is 2, can not pass in variable parameter test1 (1,5,3) #其中, x=1,y=5,z=3,y passed variable is 5, mainly applies in the default value, default installation, default port, etc. # variable group def test1 (X,y=2,*args)     print (x)     print (y)     print (*args) test1 ( 1,2,3,4,5,6) #4, 5,6 as a tuple to args, generally do not know how many variables to use, or as an extension or test1 (1,2,*[4,5,6]) def test1 (X,y=2,*args,**kwargs)     print (x)     print (y)     print (args)      print (Kwargs) test1 (1,2,3,4,5,6,name= "Alex",  sex= "M",  age=8) #4, 5,6 passed to args as a tuple, Generally do not know how many variables to use, name,sex,age, etc. as a dictionary passed to the variable, orUsed as an extension or test1 (1,2,*[4,5,6],**{"name": "Alex",  "Sex": "M",  "Age": 8}) The above variable forms can be combined, and finally it must be noted that The keyword variable cannot be written after the position variable.





Python Learning record-2016-01-19

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.