Alibabacloud.com offers a wide variety of articles about full stack development tutorial, easily find your full stack development tutorial information here online.
functionFunctional programming: As much as possible to write a sequence of nested function callsfunction is the basic unit of process-oriented program designFirst-class citizens: Functional status and data variables, variable objects initialize values, do parametersParameters unchanged, one execution = = multiple executions==============================================def custom Function Def hi (): ... return..Lambda anonymous function Fn=lamda x:x**2 (square)function.partial function Encapsula
formal parameter one by one in Init . The object's property 1 #查看对象的属性, directly with the object name. Method Name () #调用类中的方法, directly with Object name. Method Name () to Ix. Interaction between objects#人狗大战小程序class Person: def __init__ (self,name,aggr,life_value): self.name=name self.aggr=aggr Self.life_value=life_value def attack (Self,dog): #人可以攻击狗 dog.life_value=dog.life_value-self.aggrclass Dog : def __init__ (self,name,aggr,li
without right7The8>>li[2:]#If you want to go to the last data, you don't write any data .94,'a' TenGT;GT;LI[-2:-1]#You can also have negative slices One4,'a' A List add element:1>>li = [1,3,4]2>>li.append ('a')#add an element at the end3>>Li4[1,3,4,'a']5>>li.insert (2,'b')#add an element at a specified location6>>Li7[1, 3,'b', 4,'a']8>>li.extend ([2,'C'])#add multiple elements, which is the extended list9>>LiTen[1, 3,'b', 4,'a', 2,'C']List search:1 >>li = [1,3,'b', 4,'a', 2,'C
IP and port
Executes the baseserver.__init__ method, assigning a custom inherited class Myrequesthandle from Socketserver.baserequesthandler to self. Requesthandlerclass
Executes the Baseserver.server_forever method, while the loop is always listening for client requests to arrive ...
When a client connection arrives at the server
Executes the Threadingmixin.process_request method, creating a "thread" to handle the request
Execute the Threadingmixin.process_request_thread me
its cascade is defined by the Z-index property.If you set position:relative, you can use Top,bottom,left and right to move this element relative to where the element should appear in the document. [meaning that the element actually still occupies the original position in the document, but is visually moved relative to its original position in the document]4 Absolute Absolute: objects are out of normal document flow and are absolutely positioned using attributes such as Top,right,bottom,left. An
statementIf condition 1:code blockElsecode block2) Nesting modeIf condition 1:If condition 2:......3) If elifWhile loopWhile condition:code block (until the condition is not met)Ps:Continue: Exiting the current loopBreak: Exit the entire loop6. Practice1) use while loop input 1 2 3 4 5 6 8 9 10num = 1 while num : if num! =7 :print num = num + 12) for all numbers of 1-100 andnum = 1= 0 while num : = sum +num = num + 1print sum3) All odd numbers in the output 1-100num = 1 whil
write a format formater1, so you can Logger.addhandler (stream_handler) return Loggerlogger = MyLogger (' Logging.log ', File=false) logger.warning (' Cheerleader ') logger.debug (' Debug message ') The Ogging library provides multiple components: Logger, Handler, Filter, Formatter. The Logger object provides an interface that the application can use directly, handler sends logs to the appropriate destination, and filter provides a way to filter the log information formatter specify the log dis
then specify the callback function (the main process is responsible for executing) so that the main process eliminates the I/O process when executing the callback function, and the result of the task is directly obtained. #回调函数 (small example of downloading a webpage) from multiprocessing import Poolimport Requestsimport Osimport timedef get_page (URL): Print (' If you wait for all the tasks in the process pool to finish executing in the main process and then process the results uniformly, you
(status) + 1 Cp.set (user_name, ' status ', str (status)) with open (' user.conf ') , ' W ') as Fw:cp.write (fw) If status = = 3:print ("Your username is lo cked! Your administrator ") Break Else:print (" You input the username or pas Sword is wrong, try agin!! ") Count_other = count_other + 1 if Count_other = = 3:break Continue Else:co NF = configparser. Configparser () # write config file conf.add_section (' user ') #添加section # Add Value conf.set (' User ', ' user ', ' Ji MMY,AAA,
^
Match the start of a string
$
Match the end of a string
\w
Match non-alphabetic or numeric or underscore or kanji
\d
Match non-whitespace characters
\s
Match non-numeric
A|b
Match character A or character B
()
Matches an expression within parentheses, and also represents a group
[...]
Match characters in a character group
[^...]
Y, X is false, and the value is x;3. Not false is neither true nor false.Three-coding problem1. InterpreterThe PYTHON2 interpreter encodes the content with "ASCII";The PYTHON3 interpreter encodes the content with "UTF-8".2. Development of the coding systemASCII (US standard Information Interchange code) 8 bit 1 byte extended use limited;GBK (GBK compatible ASCII) 2 byte in China onlyeg: letter a:0100 0001 # ASCIILetter a:0000 0000 0100 0001 #
can bebetter maintenance and development.1. Define a functionDef creat_people ():Print ("Tuan clay, pinch clay figurines")Creat_people ()2. Adding featuresDef creat_people ():Print ("Watering") #增加功能 (but changed the code, not in accordance with the open closure principle)Print ("Tuan clay, pinch clay figurines")Creat_people ()"""Adorner Execution Flow1. Visit Warter (create_people) first.2. Pass your sign function to the parameter fn of the warter.
(10): Time.sleep (0.5) Print('Thread:', I,os.getpid ())if __name__=='__main__': T= Thread (target=func) T.start () Time.sleep (1) Print('In main 1', Os.getpid ()) Time.sleep (1) Print('In main 2', Os.getpid ())the main thread and the child thread are in the same process3. Efficiency test fromMultiprocessingImportProcess fromThreadingImportThreadImport Timedeffunc (num):Print(num**num)if __name__=='__main__': P_lst=[] Start=time.time () forIinchRange (50): P= Process (Target=func,
('\033[1;32m The green light \033[0m') E.set ()defcar (E, i):if notE.is_set ():Print('car%s waiting for a red light'%i) e.wait ()Print('car%s through'%i)if __name__=='__main__': E=Event () traffic_light1= Process (Target=traffic_light, args=(E,)) Traffic_light1.daemon=True traffic_light1.start () Li= [] forIinchRange (10): P= Process (Target=car, args=(E, i)) P.start () Li.append (p) time.sleep (random.randint (0,3)) forPinchLi:p.join ()Print('The main program is over! ')example of even
the configuration file2.1.1 View Import configparserconfig=configparser. Configparser () config.read('example.ini')print(' bitbucket.org' in config)print(config[' bitbucket.org'['user'])2.1.2 to traverse the key of a file2.1.3 Increase ImportConfigparserconfig=Configparser. Configparser () Config.read ('Example.ini')Print('bitbucket.org' inchconfig)Print(config['bitbucket.org']['User']) config.add_section ('Haibin') Config.set ('Haibin','K1','value') with open ('Example.ini','W') as
These days studied the use of pycharm.
Template: New: File---"Settings---" File and code Templates---"Pythonscript add header
#!/user/bin/env python #-*-coding:utf-8-*----------------------"OK
Text Size
File---"Settings---" Editor---"Font---" size 18
Run
A. Click on the file that you want to run right-click Run B.view---Toolbar Select the file you want to execute tap---. Right button in the current file blank
Toggle version of Python
File--
codeelse: otherwise (i.e. "the above conditions are not valid")Y + = I executes this codePrint S-yB. Complex processesName = raw_input (' Please input your name: ')If name = = ' Shaw ': condition 1 establishedprint "Hello Handsome!" "The implementation of this paragraphelif name = = ' Stiven ': Condition 2 establishedprint ' You're OK ' to perform this sectionelif name = = ' Sam ': Condition 3 establishedPrint ' Why are you so sad ... ' To perform this sectionElse: The above conditions are not
') dd[' key1 '] = ' abc ' Print (dd[' Key1 ']) # Key1 presence Print (dd[' Key2 ']) # Key2 does not exist, returns the default value CounterThe purpose of the counter class is to track the number of occurrences of a value. It is an unordered container type, stored in the form of a dictionary key-value pair, where the element is counted as the key and its count as value. The count value can be any Interger (including 0 and negative numbers). The counter class is similar to bags or multisets in o
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.