1, Python 2.x by default is ASCII encoding does not support Chinese, so when the code is in Chinese, you need to add #coding=utf-8 to the top line of the file. Python 3.x does not have this problem.
1, in Python, identifiers are composed of letters, numbers, and underscores.
2, in Python, all identifiers can include English, numeric, and underscore (_), but cannot begin with a number. The identifiers in
3, Python are case-sensitive.
4, an identifier that begins with an underscore has a special meaning. A class attribute that begins with a single underscore (_foo) cannot be accessed directly, and is accessed through the interface provided by the class and cannot be imported with "from XXX import *";
5, which begins with a double underscore (__foo) represents a private member of a class, with a double underscore (__ FOO__) Represents a special method-specific identifier for Python, such as __init__ (), which represents the constructor of a class.
6, reserved characters
Andexecnot
assert finallyor
Breakforpass
classfromprint
Continueglobal RA Ise
Defifreturn
Delimpor ttry
elifinwhile
Elseiswith
except Lambdayield
7, lines and indents
This is the biggest difference from the Java and other languages is not {()} such parentheses to define a block of code, instead of using a Space or tab (tab) indentation,
The indentation of the same block of code is the same, otherwise the code will error.
indentationerror:unexpected Indent
8. Logical lines and physical lines of Python code
Logical line: The code snippet represents the same operation
Physical line: A line of code actually displayed
If a logical line of code occupies multiple physical rows, the backslash "\" can be used to connect.
But for lists, tuples, dictionaries, and so on () []{} contains data whose code does not need to be labeled as a backslash when multiple physical rows exist.
9. Strings are enclosed in (") (" ") (" "") ("" "), and the use of three quotation marks does not require the addition of backslashes when a logical line takes up multiple physical rows.
10. Python Annotations
1) Single-line comment using #xxxxxxxx
2) Multiline comments using three single quotes or three double quotes
11. If you want to display multiple logical lines in the same physical line at the end of each logical line, add a semicolon ";".
Python Numbers (numeric) string (string) list (list) Tuple (tuple) Dictionay (dictionary) 5 standard data types
1, number contains int long float complex
1) int shaped like 100-100-0x260
2) long like 128l-12312l 0xDEFABCECBAEl tail upper case L (recommended) or L.
3) float shaped like 0.0 121.9-123.88
4) complex shaped like 1+2j
2. String
1) The order of the strings from left to right is from 0 to string length-1, the default index from right to left is calculated from 1
2) segmentation function [M,n] Note that the packet is left without packet right, if not input means intercept all.
3) * Repeat operation, + = connect operation
3. The data in the list [] list can be either a character, a number, a string, or a nested list
1) The order of the list from left to right is from 0 to string length-1, the default index from right to left is calculated from 1
2) segmentation function [M,n] Note that the packet is left without packet right, if not input means intercept all.
3) * Repeat operation, + indicates connection operation.
4) Re-assignment operation List[x] = xxxx.
4, meta-group ()
1) A tuple is a read-only list, and he cannot perform assignment operations relative to the list.
5. Dictionary {}
1) The difference between a dictionary and a list is that the dictionary obtains value by key rather than by offset.
2) Dict.keys () Show all keys
3) dict.values () Show all values
6. Del variable name can delete reference to Java-like String xx = null;
7. Conversion of Python data types
int (x [, Base]) converts x to an integer
Long (x [, Base]) converts x to a long integer
Float (x) converts x to a floating-point number
Complex (real [, Imag]) creates a complex number
STR (x) converts an object x to a string
REPR (x) converts an object x to an expression string
Eval (str) is used to calculate a valid Python expression in a string and returns an object
Tuple (s) converts a sequence s to a tuple
List (s) converts the sequence s to a list
Set (s) is converted to a mutable set
Dict (d) Create a dictionary. D must be a sequence (key,value) tuple.
Frozenset (s) converted to immutable collection
Chr (x) converts an integer to one character
UNICHR (x) converts an integer to a Unicode character
Ord (x) converts a character to its integer value
Hex (x) converts an integer to a hexadecimal string
Oct (x) converts an integer to an octal string
1. Arithmetic operators
=-*/% *//corresponding subtraction take Yu Yu multiply divide
2. Comparison operators
= = = <> > < >= <= corresponds equal to or unequal to less than or greater than or equal to
3. Assignment operation
4, bit arithmetic
& | ^ ~ << >> Bitwise OR with or not left shift right
5. Logical operation
And or not similar to & in Java |!
6. Member arithmetic
In, not in whether an object is in a list or a tuple object
7. Identity operator
Is,is not similar to Java's equal bar
8, the operation of the priority power multiplication of the highest level, the general use of parentheses, to avoid ambiguity.
Python Learning-Basic syntax