First, the installation of Python
1. Download Python installation package https://www.python.org/
2. Select the corresponding Python version (under Windows)
3, installed after the computer to open the CMD, verify that the installation is successful, mainly to see the environment variables are not set, in the cmd input python, and then enter, if the version of Python appears the software installed.
4, the previous step verification failure may be the environment variable is not set, continue to enter the command line set path, the system environment variable opened the path variable, see if there is no Python directory (such as), if not, you can only manually to add.
Ii. Variables for Python
variables, variable quantities, used to store data; A variable is a storage location and an associated symbolic name, which contains some known or unknown quantities or information, or values.
1. Declaring variables
name = "ZM"
The code above declares a variable named: Name, and the value of the variable name is: "ZM"
2. Naming conventions for variables
L variable names can only be any combination of letters, numbers, or underscores
L The first character of a variable name cannot be a number
L The following keywords cannot be declared as variable names
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']
3. Assigning values to variables
Name = "ZM" name2 = name print (name,name2) name = "Jack" Print ("What value is now printed name2")
Third, the data type
1. Digital
int (integral type)
On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807
Long (integer)
Unlike the C language, Python's long integers do not refer to the positioning width, that is, Python does not limit the size of long integer values, but in fact, because of limited machine memory, we use a long integer value can not be infinite.
Note that, since Python2.2, Python automatically converts integer data to long integers if an integer overflows, so it does not cause any serious consequences if you do not add the letter L after long integer data.
Float (float type)
A floating-point number is used to process real numbers, which are numbers with decimals. Similar to the double type in C, accounting for 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one represents the symbol.
Complex (plural)
The complex number consists of real and imaginary parts, the general form is X+yj, where x is the real part of the complex, and Y is the imaginary part of the complex, where x and y are real numbers.
Note: Small number pools exist in Python:-5 ~ 257
2. Boolean value
True or false; 1 or 0
3. String
"Hello World"
string concatenation of all evils:
The string in Python is represented in the C language as a character array, and each time a string is created, it needs to open a contiguous space in memory, and once you need to modify the string, you need to make room again, and the Evil + sign will re-open up a space within each occurrence.
String formatted output
Name = "ZM"
Print ("My name is%s"%name)
PS: string is%s; integer%d; floating-point number%f
String Common functions:
Remove blank: Strip ()
Split: Name.split ()
Length: Len (name)
Index: Name.index ("Z")
Slices: [0:3]
4. List
Create List:name_list = ["Zm", "Zm01", "Zm02"]
Basic operation:
Index: Name_list.index ("Zm")
Slice: name_list[0]
Append: Name.append (), add to the last position of the list
Delete: Del name_list[1], delete the string where the 1 position is located; name_list.remove["Zm"], delete the string
Length: Len (name_list)
Slice: name_list[]
Sort: Names_list.sort ()
Number of occurrences in the statistics list: Name_list.count ("Zm")
Iv. Data Operations
Arithmetic operations:
Comparison operation:
Assignment operation:
Logical operation:
Member Operations:
Identity operation:
Bit operations:
Operator Precedence:
V. Expressions of If...else
The If statement refers to a programming language (including C language, C#,vb,java, assembly language, etc.) used to determine whether the given condition is satisfied, according to the result of the decision (true or false) to determine the execution of one of the two operations. If the return value is true or FALSE, it can be stored with a bool variable, occupying one byte.
Use elif expression When multiple judging conditions are required
Note: The first time to write this thing (blog #17), after more research to improve ...
Python Basics 1-variables, operators, expressions