Python built-in type (2) -- Boolean operation, python Boolean
In python, the bool operators are sorted by priority.or,and,not, Whereor,andShort-circuit Operator
notTest the true value of the expression before obtaining the inverse value.
notThe operator has only one expression,notTest the true value of the expression a
The path to Python development article 2 (1) _ data type built-in function usage, the path to python GrowthData Type built-in function usage int
There are many built-in methods. Here is a summary.
(1) _ abs _ (...) returns the absolute value of x.# Returns the absolute value of x !!! All are double underscoresX. _ abs _ () For example:#! /Usr/bin/pythonPrint "abs
) Change the value within a range list[n:m] = t. T represents a value that can be iterated, and the number must be consistent with the scope of the substitution(3) Delete element Del. Another way to delete a range x[0:2] = [] equals an empty sequence is also a delete(4) List.remove (x) deletes a value. If the same value is the same, the first matching value is deleted(5) List.clear () empty list(6) Append element list.append (x) and extension element
See this topic you may guess what I want to say next, oh, yes, that is the list of these two different versions of the But not!
You'll find that Python has two major versions, Python2 and Python3, but Python is different from other languages, backward-compatible, and Python3 is backward-compatible, but most of the components and extensions are based on Python2, Here's a summary of the difference between Py
,open(‘log2‘) as obj2:pass
Program Exercises
Program 1: Implement a simple shell sed replacement function
Program 2: Modify the Haproxy configuration file
Demand:
Demand Original configuration file
6. Character encoding and transcoding
Detailed article:
Http://www.cnblogs.com/yuanchenqi/articles/5956943.html
Http://www.diveintopyth
Self-taught Python 9 crawler practice 2 (meitu welfare), python Crawler
As a young man with ideas, culture, and morality in the new century, in this society, I am so distressed that I am playing slowly to resist Baidu, it's okay to go online and visit YY. It's essential to look at the beautiful pictures. However, although the beautiful pictures are difficult to f
Recently in learning Python, like many beginners, the beginning of a more tangled in the end is version 2 or version 3 is the future trend. In order to avoid too many detours, special online Check the relevant information, summed up some 2 and 3 differences, a lot of content is reproduced, the great God do not despise ha ...
1. Performance
The Py3.0 runs Pystone
Recently in learning Python, like many beginners, the beginning of a more tangled in the end is version 2 or version 3 is the future trend. In order to avoid too many detours, special online Check the relevant information, summed up some 2 and 3 differences, a lot of content is reproduced, the great God do not despise ha ...
1. Performance
The Py3.0 runs Pystone
(1, num_num + 1)Print "BEFORE:", fac_list
I = 0
While I If num_num % fac_list [I] = 0: # Check whether the input number can be divisible by an element in the list.Del fac_list [I]I = I + 1
Print "AFTER:", fac_list[Execution result]Enter a number: 12BEFORE: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]AFTER: [2, 4, 5, 7, 8,
While loop 1. Basic cycle
123456
while条件:# 循环体# 如果条件为真,那么循环体则执行# 如果条件为假,那么循环体不执行
2. BreakBreak to exit all loops
1234
whileTrue:print "123"breakprint"456"
3, continueContinue is used to exit the current loop and continue the next loop
1234
whileTrue:print "123"continueprint"456"
Exercises1. Use while loop input 1 2
new dictionary whose key is the value of the original dictionary with the key of the original dictionary1D1 = {'Zhang': 123,'Wang': 456,'Li': 123,'Zhao': 456}2D2 = {}3 forName,roominchD1.items ():4 ifTheinchD2:5 d2[room].append (name)6 Else :7D2[room] =[Name]8 PrintD2View CodeTwo, set (set)1, set: unordered element set, similar to dictionary, but no value2. Create:x = Set ()X={key1,key2,....}3. Add and removeX.add (' body 'X.remove (' body ')4, set of operators:-: Difference Set: Inter
): - ifSelf.is_empty: - RaiseQueueemptyexception ('error:trying to dequeue element from an empty queue') AFront =Self.queue[0] +Self.queue = self.queue[1:] the returnFront - $ defClear (self): theSelf.queue = [] the the the defTest (queue): - Print('\ninit Queue:') inQueue.init ([1, 2, 3, 4, 5, 6, 7]) the queue.show () the About Print('\nenqueue element to queue:'
application. The pizza example is particularly interesting because it takes a lot of steps to get a pizza ready, and these operations follow a specific order. To add seasonings, you have to prepare the dough first. To add ingredients, you need to add seasonings first. The pizza can only be baked when the seasoning and ingredients have been placed on the dough. In addition, each pizza usually requires a different baking time, depending on the thickness of the dough and the ingredients used.The c
Python small algorithm (2), python Algorithm
There are two sequences a and B, all of which are n in size. The values of the sequence elements are unordered due to arbitrary integer numbers;
Requirement: by exchanging elements in a and B, the deviation between [Sum of Element a] and [Sum of Element B] is minimized. (Huawei interview)
Def diff (sorted_list, leng
.2cto.comNow, assume that you have a messy HTML file called messy.html. The following program runs Tidy on the file and prints the result:
3. Use HTMLParser: After the XHTML code in good format is obtained above, we can use the standard library module HTMLParser for parsing. We only need to inherit HTMLParser and overwrite the event handling methods such as handle_starttage or handle_data. Summarizes some related methods and when the parser automatically calls them.
The following code uses the H
;> f. write ('this is 1st line. \ n') >>> f. write ('this is 2nd line. ') >>> f.close(**somefile.txt file content This is 1st line. this is 2nd line.Example of simple reading:
>>> F = open('somefile.txt ', 'R') >>> f. read (16) # first read 16 characters 'this is 1st line' >>> f. read () # The remaining content will be read, unless the seek is located at 0 and re-read '. \ nThis is 2nd line. '>>> f. close ()MPs queue output
$ Cat somefile.txt | python
> >> Isinstance (ITER ('abc'), Iterator)4 TrueYou may ask, why, list dict , str etc. data types are not Iterator ?This is because the Python Iterator object represents a data stream, and the iterator object can be next() called by the function and will return the next data continuously until there is no data to throw an StopIteration error. You can think of this data stream as an ordered sequence, but we can't know the length of the sequence in advan
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.