Basic concepts
Python basic information
-
The father of python is the Dutch Guido van Rossum
-
Python provides a complete basic code base, covering a large amount of content such as network, files, GUI, database, text, etc.
-
In addition to built-in libraries, Python also has a large number of third-party libraries
-
Python is suitable for application
- Web application (website, background service)
- Everyday gadgets, scripts
- Package other language programs
-
Disadvantages
- Slow running speed: interpreted language, the translation process is very time-consuming, and C language can be compiled, running fast (but still very fast)
- Can't encrypt: python program is to release source code, C can be exe, java can be jar
python interpreter
CPYthon
The official version of the interpreter, this interpreter is developed in C language, so it is called CPython, when you run python on the command line, it starts the CPython interpreter
CPython interpreter is the most widely used Python interpreter
>>>
Is the prompt
IPython
It is an interactive interpreter based on CPython, but the interaction is enhanced, but the function of executing Python code is exactly the same
In []:
Is the prompt
Pypy
Using JIT technology, dynamic compilation (not interpretation) of Python can significantly improve the code execution speed.
The execution of the same code under CPython and Pypy may have different execution results.
JPython
The Python interpreter running on the Java platform can directly compile Python code into Java bytecode
IronPython
The Python interpreter running on the .Net platform can directly compile Python code into .Net bytecode
If you want to interact with the Java or .Net platform, it is best to call through the network instead of changing the interpreter
python installation
Mac
mac OS X> = 10.9 system comes with python2.7, if you want to upgrade 3.8, there are two methods:
1. Download the 3.8 installer from the python official website and double-click to install
2. If there is Homebrew,brew install python3
linux
Linux comes with python
Download python3 method
1. Download the official software package
2. Unzip
3. Prepare the compilation environment
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
4. Compile
(1) ./configure --prefix=<path>/Pythonxxxx
(2) make
(3) make install
5. Create a soft link
ln -s <install-path> /usr/local/bin/python3
6. Configure environment variables
Open configuration file
vi ~/.bash_profile
Add configuration
export PYTHON_HOME=<path>/Pythonxxx
export PATH=$PYTHON_HOME/bin:$PATH
Effective configuration
source ~/.bash_profile
echo $PYTHON_HOME # 查看
windows
Download the installation package on the official website and install it directly. Remember to check Add environment variable on the installation option, otherwise add it yourself
1. 进入修改环境变量选项卡
2. 在系统变量PATH中添加python安装路径
3. 保存
Python runs
# 方法一:
启动解释器,逐行输入代码
# 方法二
python filename.py
# 方法三(linux mac)
chmod a+x filename.py
./filename.py
-
Enter:
input('hint')
-
Output:
print()
-
Notes:
#