Types of Erpython:
- The official version of Cpython Python, implemented using the C language, is the most widely used, and the Cpython implementation converts the source file () (py file) into a bytecode file (PYc file) and then runs the Python virtual machine.
- Jython Python's Java implementation, Jython will dynamically compile Python code into Java bytecode, and then run on the JVM
- IronPython Python's C # implementation, IronPython compiles Python code into C # bytecode and then runs on the CLR (similar to Jython)
- Python implemented by PyPy (special) Python, which compiles Python bytecode into machine code
- Rubypython, Brython
Python environment
To install Python:
Windows:
1. Download the installation package: https://www.python.org/
2. Install the default installation path: C:\python27
3. Configure environment variables: "Right-click Computer"-"Properties"-"Advanced system Settings"-"Advanced"-"Environment variable"-"in the second content box to find the variable named path of a row, double-click"-"Python installation directory appended to the variable value, with; such as: the original value; C:\python27, remember that there is a semicolon in front
Linux:
1. No installation, original Python environment PS: If bring 2.6, please update to 2.7
Update Python:
Windows: Load Unloading
Linux:linux Yum relies on its own python, to prevent errors, the update here is actually to install a python
View the default Python version
Python-v
1. Install gcc for compiling python source: Yum install gcc
2. Download the source package,https:
/
/
www.python.org
/
ftp
/
python
/
3. Unzip and enter the source file
4. Compiling the installation
./configure
Make all
Make install
5. View version
/usr/bin/local/bin/python2.7-v
6. Modify the default Python version
mv/usr/bin/python/usr/bin/python2.6
In-s/usr/local/bin/python2.7/usr/bin/python
7. To prevent Yum from performing exceptions, modify the Python version used by Yum
Vi/usr/bin/yum
#! the head /usr/bin/python modified to #! /usr/bin/python2.6
Getting Started with Python
One, the first Python code
Create the hello.py file under the/home/dev/directory, as follows:
Execute the hello.py file, i.e.: python/home/dev/hello.py
The Python content executes as follows:
II: Interpreter
When executing python/home/dev/hello.py in the previous step, it is clear that the hello.py script is executed by the Python interpreter. If you want to execute a python script like Jade execution shell script, for example:./hello.py, then you need to specify the interpreter in the header of the hello.py file, as follows:
As a result, execute:./hello.py.
PS: Need to give hello.py execute permission before execution, chmod 755 hello.py
Third, Content coding
Tell the Python interpreter what code to use to execute the source code, i.e.:
Iv. notes
When line comment: #被注释的内容
Multiline Comment: "" "Annotated Content" ""
V. Execute script incoming parameters
Python has a large number of modules, which makes developing Python programs very concise. There are three types of class libraries:
- Python-supplied modules
- Industry-Open Source modules
- Modules developed by programmers themselves
Python provides a sys module inside, where SYS.ARGV is used to capture parameters passed in by the Python script
Vi.. pyc file
When you execute a python code, if you import a different. py file, it is automatically generated with the same name as the execution. PYC file, which is the bytecode generated by the Python interpreter after compilation.
PS: Code is compiled to generate bytecode, and bytecode can be obtained by decompile.
Seven, variable
1. Declaring variables
The code above declares a variable named: Name, and the value of the variable name is: "Zhangsan"
The role of a variable: a nickname that refers to what is stored in an address in memory
Rules for variable definitions:
- Variable names can only be any combination of letters, numbers, or underscores
- The first character of a variable name cannot be a number
- The following keywords cannot be declared as variable names {' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' Finall Y ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' Try ', ' While ', ' with ', ' yield '}
2. Assigning values to variables
Eight, input
When entering a password, if you want to disappear, you need to take advantage of the Getpass method in the Getpass module, namely:
IX: Process Control and indentation
Requirement One, user login verification
Demand two, according to the user input content output its permissions
code block
Else:
code block
code block
Elif conditions:
code block
Else
code block
True False
1 > 2 n1 > N2 n1==n2
Name = = "Alsex" or "name = =" Zhao "
Name! = "Zhao"
Name = = "Zhao" and pwd= "123"
Ten, while loop
1. Basic cycle
2.break
Break to exit all loops
3.continue
Continue is used to exit the current loop and continue the next loop
Python Development (second article): Initial python