Yesterday review:
file processing opens the file open (' path ', ' open mode ',' Specify the encoding method ' ) Open mode R w a r+ w+ A + b r+ open File Direct write and read re-write encoding method--utf-8 operation file
read one-time read readlines One-time read readline one line read don't know where to end video pictures rb bytes read for loops in bytes -Best!!! writes The write cursor--the file pointer seek _ specifies that the cursor moves to a location tell _ Gets the current position of the cursor truncate _ intercept file close file Close
Today's content: functions
#function Code Exercises#s = ' dsffse '#def my_len (): #定义之后, can be called from anywhere. #i = 0#For K in S:#I +=1#print (i)#length = My_len ()#print (length)#importance of the return value#def my_len ():#i = 0#For K in S:#i + = 1#return I#length = My_len ()#print (length)#three cases of return value #no return value---return none #do not write return #write return only to End Function run #return None---not used #returns a value #can return any data type #as soon as you return, you can receive #If there are multiple return, only the first one is executed #return multiple values #receive with an equal amount of variables #accept with a variable, get a tuple#def func ():#L = [' Received ', ' King boss ']#For i in L:#print (i)#if i = = ' King boss ':#return None#print (' = ' *10)#ret = func ()#print (ret)#def func ():#return {' K ': ' V '}#Print (func ())#def func ():#return#Res=func ()#Print (res)#def My_len (s):#i = 0#For K in S:#i + = 1#return I#ret = My_len (' Dasdasds ')#print (ret)#ret = My_len ([1,2,3,4,5])#print (ret)#parameter order: Position parameter, *args, default parameter, **kwargs#There are two types of dynamic parameters: #*args: Received by the value of the location parameter, organized into a tuple #**kwargs: Received by keyword, organized into a dictionary of the value of the parameter #*args must be before **kwargs#def sum (*args):#n = 0#For i in args:#n + = i#return n#print (sum ())#Print (sum (1,2,3,4))#Print (sum (1,2,3,4,5))##def func (**kwargs):#print (Kwargs)#func (a = 1,b = 2)#def func (*args,default = 1,**kwargs):#print (Args,kwargs)#func (1,2,3,4,5,6,7,default=2,a= ' s ', b= ' s ')##def func (*args):#print (args)##func (1,2,3,4,5)#l=[1,2,3,4,5]#func (*l) #站在实参的角度上, adding * to a sequence, is to break the sequence in order#def func (**kwargs):#print (Kwargs)#func (a=1,b=2)#d = {' A ': 1, ' B ': 2}#func (**d)##函数的注释## def func ():# """#Functions of the function#parameter one:#parameter two:#: Return: What is returned# """
Python Learning Day9