There is time today, add a python encounter a problem, and then extend a series of questions, about slice,step and carefully study the next stride calculation method, the results of 2 hours or so, the introduction is painful ah, gossip not much to say, directly on the problem code:
<span style= "FONT-SIZE:18PX;" >>>> a= "python" >>> print (a[::-1]) nohtyp>>> >>> print (a[:-1]) Pytho</span >
For this calculation, my understanding is that the string followed by [] is index, which indicates the indexes on the characters in string.
For example [0:n] represents the first to the n-1 character in string, which is the position of the first character with zero.
If you do not write the beginning or end, the default starts from scratch, or until the end. For example [: 3] actually is [0:3], is [0],[1],[2] these three; [3:] represents the fourth to the last. Then, if the negative number is in index, it means counting backwards from the back.
- Note that both the front and back indexes are calculated starting from 0.
<span style= "FONT-SIZE:18PX;" >a=[2,3,1]print a[-1:-2:-1]</span>
- Slice calculation of related slices
Temporary value b=[-1:-2] The actual calculated value is [], therefore, there is no such boundary value;
The calculation of the film, has been very confused, has always been thought to be a step calculation, there is an intermediate value, and then carefully checked, only to understand that there is no intermediate value, which has a concept of a step
Start, end, step
python supports list slices, which can be part of a complete list. The types of support cutting operations are str, bytes, list, tuple and so on. Its syntax is ... [Left:right] or ... [Left:right:stride]. assuming that the value of the nums variable is [1, 3, 5, 7, 8, 13, 20], then the following statements are true:Nums[2:5] = = [5, 7, 8] The element from subscript 2 is cut to the element labeled 5, but does not contain an element labeled 5. nums[1:] = = [3, 5, 7, 8, 13, 20] cut to the last element. nums[:-3] = = [1, 3, 5, 7] from the beginning of the element has been cut to the 3rd element of the bottom. nums[:] = = [1, 3, 5, 7, 8, 13, 20] returns all elements. Changing the new list does not affect the nums. Nums[1:5:2] = = [3, 7] from the subscript 1 of the element is cut to the element subscript 5 but does not contain the element labeled 5, and the step is 2.
Add=lambda x, y:x + y
- Lambda expression of Python anonymous function
1. Lambda expressions are used to create small anonymous functions that do not need to use the DEF keyword when they are created. 2. A lambda expression can have any number of arguments. 3. Lambda expressions cannot access global variables, only their own parameters4. Lambda expressions cannot output results using Print statements.
The lambda expression has only one sentence, as shown in the following form: Lambda [var1, [var2,...]]:expression The lambda expression summed is as follows: SM = lambda var1, var2:var1 +var2
Print SM (10, 20)
The program output results are: 30
- CGI means Common Gateway Interface,. A browser-based input, a program method that runs on a Web server. CGI scripts enable your browser to interact with the user. This script is often like a bridge between servers and other programs in the system such as databases.
Executable script.
The following is in the Baidu encyclopedia to find some of the foundation, to help develop their skills knowledge, posted out, not interested can not look.
Python has a rich data type built in. These data types effectively reduce the length of code compared to Java, C + +. The following list briefly describes Python's built-in data types (for Python 3.x):
type |
Description |
Example |
Notes |
str |
|
' Wikipedia ' "Wikipedia" multiple lines "" " |
|
bytes |
A byte-composed immutable serial. |
B ' Some ASCII ' B "Some ASCII" |
|
List |
Can contain a variety of types of can be changed with serial |
[4.0, ' String ', True] |
|
Tuple |
Can contain multiple types of immutable serial |
(4.0, ' string ', True) |
|
Set, Frozenset |
Similar to the concept of collections in mathematics. unordered, each element is unique. |
{4.0, ' string ', True} Frozenset ([4.0, ' String ', True]) |
|
Dict |
A non-serial that can be changed by a key-value pair. |
{' Key1 ': 1.0, 3:false} |
|
Int |
Integer with unlimited precision |
42 |
|
Float |
Floating-point number. Accuracy is related to the system. |
3.1415927 |
|
Complex |
Plural |
3+2.7j |
|
bool |
Logical value. Only two values: true, False |
True False |
|
In addition to various data types, the Python language uses types to represent functions, modules, types themselves, methods of objects, compiled Python code, run-time information, and so on. As a result, Python has a strong dynamic nature.
- Python Application areas:
- system programming: providing API ( application Programming Interface application Programming Interface), it is convenient for system maintenance and management, Linux under one of the iconic language, is a lot of system Administrator the ideal programming tool.
- graphics Processing: pil,Tkinter and other graphics library support, can be easily graphics processing.
- Mathematical Processing: The numpy extension provides a large number of interfaces to many standard math libraries.
- Text Processing:The RE module provided by Python supports regular Expressions , and it also provides sgml,xml analysis modules, and many programmers use Python for the development of XML programs.
- Database Programming: Programmers can follow Python Db-api (Database Application Programming Interface ) The canonical module communicates with Microsoft SQL Server,oracle,sybase,db2,mysql, SQLite, and other databases. Python comes with a gadfly module that provides a complete SQL environment.
- Network Programming : Provide rich module support sockets programming, can develop quickly and easily Distributed Applications . Many large-scale software development programs such as Zope, Mnet and BitTorrent. It is widely used by Google.
- Web Programming : The development language of the application, supporting the latest XML technology.
- Multimedia Applications: Python's Pyopengl module encapsulates the "OpenGL application Programming Interface" for two-and three-dimensional image processing . The Pygame module can be used to write game software.
- Pymo Engine: Pymo is all called Python memories off and is a AVG game engine running on Symbian S60v3,symbian3,s60v5, SYMBIAN3, and Android systems. Due to its development based on the python2.0 platform, and is suitable for the creation of the Autumn memory (Memories off) style of the AVG game, Hence the name Pymo.
- hacking Programming:python has a hack library with built-in functions that you are familiar with or unfamiliar with, but lack a sense of accomplishment.
- write simple crawlers in Python. first of all, to get the corresponding HTML source code by urllib2 This module .
<span style= "FONT-SIZE:18PX;" >import urllib2url= ' http://www. Baidu Com/s?wd=cloga ' Content=urllib2.urlopen (URL). Read () </span>
through the above three sentences can be the source code of the URL exists in the content variable, its type is character type. The next step is to extract the content we need from this stack of HTML sources. Use Chrome to see the code for the corresponding content (you can also use Firefox's Firebug). You can see that the information for the URL is stored in the span tag, and the information you want to get it can be used in regular style.
PS: This article only makes the record exchange, does not do his use.
References: http://baike.baidu.com/view/21087.htm
Python: The list of entry notes slices algorithms, anonymous expressions, CGI, data types, and application fields