Discover full stack development book, include the articles, news, trends, analysis and practical advice about full stack development book on alibabacloud.com
') F.writelines (['1111\n','2222\n','3333\n'] # Writes a string list to a file f.write ('aaaaa\nbbbb\nccccc\n')Summary:W: Write-only mode1. When the file is present, empty2. Create an empty document when the file does not existAppend Mode (a)#A: Append write mode only#Note:#Create an empty file when the file does not exist#when the file exists, the cursor runs directly to the end of the fileF=open ('Access.log', mode='a', encoding='Utf-8')#print (f.writable ())#f.readlines () #报错F.write ('555555
the end condition.Summarize:1. Recursion must have a definite end condition2. The size of the problem should be reduced every time the next recursion is entered3. No tail-recursive optimizations in Pythonanonymous functionsWhat is anonymous function keyword lambdaanonymity means no name . def func (x,y,z=1): return x+y+z anonymous lambda# has the same scope as a function , but anonymity means that the reference count is 0 and is used once to release, unless it has a name func=Lambda x,y,z=1:
* Specifies the length, from the beginning of the truncation, do not specify the length, from the current position to the end of all removedF.writable ()#determine if it can be writtenIii. Modification of documentsHere's a simple way to implement a file modification:#File ModificationImprot os #这里导入了os模块去改文件名f_name='C:\\users\\administrator\\desktop\\3.txt'F_new_name='%s.new'%F_nameold_str='Xinjiang'New_str='Beijing BJ'F= Open (File=f_name, mode='R', encoding='GBK') F_new= Open (File=f_new_name
While loopWhy would there be loops like this statement?To give a simple example: we want to calculate the number of even numbers within 0-100, and this time we need to loop this statementThen one might say, "What 0+2+4+.......+98 can be calculated?"Suddenly our condition changed: Calculate the number of even numbers within 0-10000000 andIt can be imagined that this is how a workload, the cycle is just to solve this problem.Figure:The representation of a while loop in Python is like.Grammatical f
type base data type:String:Number:Number.max_value,number.min_value.Nan is not equal to NanIsNaN (' Test ') #trueInfinityBoolean:Null:Undefined:Reference data type:Array: ArraysString:Date:Object:4) Data type conversion
Number + String : Number converted to string
Number + Boolean: True converts to 1,false to 0
String + Boolean value : Boolean converted to string true or False
Convert to String: toString ()
Convert
27. File A.txt content: Each line content is the product name, the price, the number.Apple 10 3Tesla 100000 1MAC 3000 2Lenovo 30000 3Chicken 10 3Through the code, build it into this type of data:[{' name ': ' Apple ', ' price ': Ten, ' Amount ': 3},{' name ': ' Tesla ', ' price ': 1000000, ' Amount ': 1} ...] and calculate the total price. "ImportOs,relst=[]with Open ('C','R', encoding='Utf-8') as F1:dic= {} forLineinchF1:li= Re.sub (r'\s{1,}',',', line). Strip (',') dic['name'],dic[' Price'
20. Determine whether a number is a narcissus number, the number of daffodils is a three-digit, three-digit each of the three-square and also equal to this number. That number is a number of daffodils, for example: 153 = 1**3 + 5**3 + 3**3num = input (" Please enter a three-digit number:"= Int (num[0]) * * 3 + int (num[1]) * * 3 + int (num[2]) **3if
int (num) = = s :print(" Narcissus number ")Else : Print (" no ")Python3.6 full
18. License plate zoning, the following license plate is given. According to the information of the license plate, the number of license plate holdings in each province is analyzed. (Upgrade question)result = {} for in cars: = locals[car[0]] = result.get (location, 0) +1print(Result)result = {} forCarinchCars#Car Brandfirst_name = car[0]#ShandongLocation =Locals[first_name]#to statistics ifResult.get (location) = = None:#If you get the current location. The number of corresponding vehic
9. Dictionary dic,dic = {' K1 ': "v1", "K2": "V2", "K3": [11,22,33]}A. Please loop out all the keysFor I in Dic.keys ():Print (i)B. Please loop out all the value for inch dic.values (): Print (i)C. Please loop out all the keys and value for inch Dic.items (): Print (I,J)D. Add a key-value pair in the dictionary, "K4": "V4", and output the added dictionaryDic.setdefault ('K4','v4')print(DIC)E. In the modified dictionary, the value of "K1" corresponds to "Alex", Output the modified diction
16. Movie Scoring: The program gives a list of several movies that are currently being released. Voted by the user for each movie.Finally, the user's voting information is published in LST = [' Beijing meets Seattle ', ' Save Mr. Wu ', ' American past ', ' the beautiful legend of Sicily ']Result: {' Beijing meets Seattle ': 99, ' Save Mr. Wu ': 80, ' The American Past ': 6, ' The Beautiful Tales of Sicily ': 23}LST = ['Beijing meets Seattle','Save Mr. Wu','The American past','the beautiful legen
11. The element classification has the following value li= [11,22,33,44,55,66,77,88,99,90], all values greater than 66 are saved to the first key of the dictionary, the value less than 66 is saved to the value of the second key.That is: {' K1 ': List of all values greater than 66, ' K2 ': List of all values less than 66}dic={'K1':[],'K2': []} li= [11,22,33,44,55,66,77,88,99,90] forIinchLi:ifI > 66: dic['K1'].append (i)Else: dic['K2'].append (i)Print(DIC)Python3.6
manipulation objectsCheck: object. Name # print (aq.name)Increment: Object. job= "Student" # aq.job= "Stu"Delete: Del object. AgeChange: Object. gent= "Male"6. The static variables in the object operation class can only be queried, cannot be deleted or modified.The object name. Variable (level) in class # print (Aq.level)7. Methods in the Object execution classThe object name. Walk () # Aq.walk () # automatically receives object space without having to pass arguments to the self position.Add: _
#class Eat:#def __init__ (self):#print (' Eat ')#def Eat (self):#print (' Eat ')##class Run:#def __init__ (self):#print (' Run ')#class Cat (eat,run):#def __init__ (self):#print (' This is a cat ')#def Eat (self):#print (' This is sons eat ')#class Dog (eat,run):#def __init__ (self):#print (' This is a dog ')#P1=cat ()#p1.eat ()#class Father:#def __init__ (self,name,age,gender):#Self.name=name#Self.age=age#Self.gender=gender#def test (self):#print (' This is Father S ')#class Son (Father):#def _
One, yesterday content review second, today content summarizes 1.jquery introduction 1), why use jquery? 2), jquery two characteristics 3), the introduction of jquery Step 4), the entry function of Jqurey three notation 5), jquery and JS entry function of the two different points 6), Jqurey object and Dom objects to each other conversion 7), Jqurey internal Packaging principle 8), DOM2 level event is divided into three stages: 1. Capture Phase 2. In Target Stage 3. Bubbling phase (Learn)Al
typically start with uppercase def __init__ (self,age): self.age =age# gives self an age method with a value of input age,,p.age=age name=" yehaibin " # data properties # for def Qiong (self): print ( ' zhengzaitutan " ,self.age ) del china.name 2.1.4 Increase classChina:#when declaring a class, it is usually preceded by uppercase def __init__(self,age): Self.age=age#Given to self an age method, the value of the input age,,p.age=ageName='Yehaibin'#Data Properties #
,PRICE,ADDR): Self.name=name Self.priod=priod Self.price=Price self.addr=AddrclassTeacher:def __init__(self,school): Self.school=School##############School1=school ('Sdau','Beijing',{'Linux':'Class 1','python':'Class 2'})#The school is already there, let the students chooseSchool2=school ('Yingshangyizhong','Shanghai',{'Go':'Class 3'})#Create a courseLesson1=lesson ('python','50week', 150,'Beijing')#courses are available, so students can chooseLesson2=lesson ('Linux','30week', 60,'Beijing') Less
cursor movement are in bytes such as Seek,tell,truncateAttention:1. Seek has three modes of movement 0,1,2, of which 1 and 2 must be performed in B mode, but regardless of which mode is moved in bytes unitsSeek controls the movement of the cursor as a reference to the beginning of the file.Tell the position of the current cursor2. Truncate is truncated file, truncation must be write mode, but can not be opened with W or w+, because that will directly empty the file, so truncate to r+ or a or a
from the real work2: Code easier to organize, clearer, complex tasks easier to implement;3: No doubt, more secure, not due to some small negligence to make the program accidentally collapsed;Iii. when to use exception handlingTry...except should be used sparingly, because it is an exception-handling logic that you attach to your program, which is not related to your main work.This kind of things add more, will lead to your code readability is poor, only in some abnormal unpredictable circumstan
@funcname.setter.Obj.func = New_value is called by the @funcname.setter Adorner decoration methodThe method name to be decorated by @property must have the same name as the method decorated by @funcname.setter2. Another method can be modified, but the last method is called by a method in a class disguised as a property, and this methodOr the same as the original instantiation callFor example:Class people: def __init__ (self,name,age,sex,height): self.__name = name Self.__age =
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.