Installation of Python source package
Go to the python official website to download the Python source package after version 3.0.
www.python.org
unzip:
you can see some files inside.
./configure --help
Execute the script in this directory and view the help.
Among them, we can see
that the –disable parameter is added to the python program by default. When we add this option, the following options will not be added. -Enable the opposite.
./configure --prefix=/usr/local/python3
Execute the command to precompile.
No problem, compile and install
make && make install
Prompt us to drop the zilb package, and we will
compile and install again next time:
success.
But still can not use python3 command, only python2.7:
we need to enter the bin directory to execute the name command.
For ease of use, let's link it to environment variables.
ln -s /usr/local/python3/bin/* /usr/local/bin
You can use the python3 command
Simple usage of Python code
Python scripts all end with py.
Write the first script:
use python2 to execute:
two ways are possible.
Use python3 to execute:
the second syntax is not supported, which is the difference between the 2 and 3 versions.
2 does not support Chinese, 3 supports Chinese. The
code begins to add:
python2 can use utf-8 format to support Chinese
python comments
print('hello world')
# this is a comment 第一种注释方式
print('hello westos') #this is a connent 第二种注释方式
"""
they are
comment 第三种注释方式
"""
print('hello linux')
Execution effect:
Visible content is visible.
It is necessary for more complex script comments, which can help us understand the role of the code more easily.
Control input and output in Python
In Python2:
input can only recognize numeric values, not letters, so an error is reported.
We want to make it possible to report errors:
raw_input can convert the input content to a string for processing.
When we use raw_input to define a variable, we can see that its type is a string.
Use int to change it to integer. When comparing, the value of age is greater than 19 because it is compared with ASCII code,
so we generally need to convert its value to the same form when comparing.
In Python3: In
Python3, everything received is treated as a string. There is no raw_input function.
Python formatted output
% s str String
% d int Integer
% f float Floating point %%%
Two percent signs represent%
install ipython:
directly execute in rhel8: pip3 install ipython
The sequence of the contents in% behind must be consistent with the previous, otherwise Different types will report errors.
% f stands for floating point number.
When money is an integer, it will automatically fill in several 0s. .2 represents 2 0s.
Integers can also be filled, 1 is not enough for three, so it is 001.
%% means%
scale * 100 = 0.1 * 100 = 10