1.python origin and version
Python was launched in 1989, and now it's up to 3.5, with a maximum of 2.x.
The main differences between version 3.x and 2.x are as follows:
3.x does not have to define character set types individually, default is Unicode;
Print () instead of print;
Input replaces the raw_input,2.7 version of input and raw_input can be used, but not exactly the same, 2.7 input without quotation marks when the variable processing, to enter a string to be quoted, and more than 3.0 version input string without quotation marks;
A lot of repeated methods are removed, the method name is normalized, and the method name with the beginning of _ is renamed;
Since many of the projects on the market were developed in the 2.x version, the 2.7 version was developed for a smooth transition, which is compatible with the 2.x and 3.x syntax
2.python Development Tools
Common IDE tools are Pycharm
3. Variables
Variable names can only be composed of alphanumeric underscores;
Variable names cannot begin with numbers and symbols;
The variable name cannot be the same as the keyword;
4. Indenting Python is indented in the control format, the next level of code indents four spaces to the right, and the IDE tool indents four spaces by tapping the TAB key.
5. Conditional Judgment and circulation
Conditional judgment
If
Elif
Else
Execution order from top to bottom, when if and elif are not satisfied, do else
Cycle
While
Keyword True cannot be used when a variable is assigned a value
While:else:
For:else:
The else is executed when the loop exits normally, and if the loop is an unhealthy exit, such as break, the following else will not be executed.
6. Common data types
Digital
Int
Long
Float
Boolean
String
List
Dictionary
7. String formatting
%s print ("This is%s"% ("string"))
%d
%f
Content Block Input:
BSG = "'
‘‘‘
8. List Common operations
Rang ()
Take position index (only the first occurrence of the element to be taken): index ()
Added: Append ()
Remove: Remove ()
Count: Count ()
Shard: Name_list[1:5] by one shard from the beginning to the 4th position. Name_list[1:5:2] Press Start to 4th position every two shards.
9. File operation
File = open (' File name ', ' mode ')
Read () reads the entire content
ReadLine () read by row
Mode:
R: Read-only
W: Write only, will empty the original file contents
r+: Read and Write
W+: Reads, clears the original file contents
This article is from the "11100818" blog, please be sure to keep this source http://11110818.blog.51cto.com/11100818/1736669
Python Learn the first chapter essentials