Python is an object-oriented, literal translation computer programming language. The recognized characteristics are simple, easy to learn, free and open source. Personally, what I particularly like about Python is its flexible manipulation of strings, simple and clear indentation (although Baidu Encyclopedia describes this as a restriction), and simple grammar.
Python, like C, is done sequentially, instead of visual c++ being triggered by different modules. The operation is similar to matlab. There is an editing window and a running window (interactive interpreter), which can be written and run, or can be completed one by one by command line.
2. Basic grammar
2. 1 expression, number,/(divisible),% (remainder), * * (power), # comment;
2.2 long shaping (followed by l); Hexadecimal and octal (0x and 0s like c);
2.3 variable assignment (x=2), statement, input and output (input ("haha"), x = input ("");
2.4 functions: abs () and round () are rounded.
2.5 Module: Import Mathematics
3. Line
3. 1 single quotation marks and escape characters
In Python, single quotation marks and double quotation marks have basically the same function. Double quotation marks are usually contained in quoted strings, so they are used to distinguish them. Another way is to escape with/. Escape means that the last character is treated as an ordinary character and has no function of its own.
3.2 string representation
Use'+'to splice strings, for example, x x =' a' y =' b' z = x+y+y.
String representation: str: Convert the value into a reasonable form of string for users to understand.
Repr or' x': Create a string to represent the value as a legal Python expression.
Long string: If the string is too long, you can use three quotation marks instead of ordinary quotation marks. Or use/escape a line break at the end of each line.
Original string: r'' will not escape/,but will keep the original writing of all characters in the string.
3.3 string format
This is similar to C. The format operator (%) is used to specify the length, precision, alignment and so on.
3.4 String method
The string method is similar to the sequence method: object. Method. Commonly used are the following:
Find: Find a substring in a string and return the leftmost index of the substring; otherwise, return-1.
& gt& gt& gt I'm from China.
& gt& gt& gttitle.find('chi ')
& gt& gt& gt eight
Note: You can also specify the range: title.find (',0, 16), that is, from the first to 16.
Join: Add an element to the queue.
& gt& gt& gtsep="+"
& gt& gt& gtseq=[' 1 ',' 2 ',' 3 ',' 4 ',' 5']
& gt& gt& gt detach connection (sequence)
& gt& gt& gt' 1+2+3+4+5'
Lower: Returns the lowercase version of the string.
& gt& gt& gt I come from China. Lower part ()
& gt& gt& gt I'm from China.
Replace: Returns the string after all the matches of a string have been replaced.
& gt& gt& gt This is a test. Replace ('Yes',' eez')
& gt& gt& gt This is a test.
Split: the inverse method of join, which is used to split a string into sequences.
& gt>'1+2+3+4'. Split ("+")
& gt& gt& gt[' 1','2','3','4']
Strip: Returns a string with both sides of spaces removed (excluding internal spaces):
& gt& gt& gthh Dihh. Strip ()
& gt& gt& gthh dihh '
Note: You can also specify the characters to be deleted, just list them as parameters. Note that only the two sides will be removed, and the middle will not be removed.
Translate: similar to replace, but only dealing with a single character, the advantage is that multiple substitutions can be made at the same time.
3.5 Strings and sequences
The list function can convert a string into a sequence. See the next section for the operation of the sequence. The only difference from the standard sequence is that it is immutable and cannot be x[2]='c'
Step 4: Order
4. 1 universal sequence operation
Index: such as the subscript of C.
Segmentation: [3 (initial): 6 (excluding the first bit of the rest after segmentation)] [-3:- 1] [0: 10:2 (step size)]
Sequence addition and multiplication:+*
In: Returns a Boolean value whether it is in the sequence or not.
Length, maximum (minimum) value: len() max()min ()
4.2 List
4.2. 1 basic list operation
Element assignment, partition assignment (very interesting operation)
tabulation method
Object. Method (parameter)
Append: used to append a new object at the end of the list.
Count: Count the number of times an element appears in the list.
Extension: You can append multiple values to the end of another sequence at a time.
Index: the index position used to find the first matching value in the list.
Insert: used to insert an object into the list.
Pop: Deletes an element from the list (the last one by default) and returns the value of the element.
Remove: used to delete the first value in the list.
Invert: Invert the elements in the list.
Sort: Sort in the original position.
===============================================================================================
Python is needed for internship in the school laboratory this holiday, but the requirements are not high. Programs that need to be compiled in python are actually very simple. In addition, I used to have the foundation of C language and delphi, but I just read python books in general. What I really want to say here is that sometimes the learning method of learning while using and finding while using is very efficient! !
Python gives me the greatest feeling that it is flexible and simple. Grammar is very close to the habit of natural language, especially when dealing with strings. I don't need to rack my brains like I did when preparing ACM. I like python very much! !