Dictionary
Characteristics:
- No order
- Go heavy
- Fast query speed, much faster than the list
- 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