Python Learning Note--day 3

Source: Internet
Author: User
Tags define local variable scope

Dictionary

Characteristics:

    1. No order
    2. Go heavy
    3. Fast query speed, much faster than the list
    4. Consumes more memory than list
Function

Non-fixed parameters:

If your function is not sure how many parameters the user wants to pass in the definition, you can use the non-fixed parameter

def stu_register (Name,age,*args): # *args will turn multiple incoming parameters into a tuple form    print (Name,age,args) stu_register ("Alex") #输出 #alex () #后面这个 () is args, just because there is no value, so the empty Stu_register ("Jack", "+", "cn", "Python") #输出 # jack (' cn ', ' Python ')

can also have a **kwargs

def stu_register (Name,age,*args,**kwargs): # *kwargs will turn multiple incoming parameters into a dict form    print (Name,age,args,kwargs) stu_ Register ("Alex", "#alex") #输出 () {} #后面这个 {} is Kwargs, just because there is no value, so the empty Stu_register ("Jack", "+", "CN", "Python", sex= "Male", Province= "Shandong") #输出 # Jack (' CN ', ' Python ') {' Province ': ' Shandong ', ' sex ': ' Male '}

Global variables and local variables:

A variable defined in a subroutine is called a local variable, and a variable defined at the beginning of the program is called a global variable. The global variable scope is the entire program, and the local variable scope is the subroutine that defines the variable. When a global variable has the same name as a local variable: Local variables work within subroutines that define local variables, and global variables work in other places. anonymous function: A specified function that does not need to be displayed
#这段代码def Calc (n):    return N**nprint (calc) #换成匿名函数calc = Lambda n:n**nprint (Calc (10))

  

res = map (lambda x:x**2,[1,5,7,4,8]) for I in Res:    print (i)

  

Python Learning Note--day 3

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.