Installation and basic input and output of Python3 source package

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:
Insert picture description here
you can see some files inside.

./configure --help

Execute the script in this directory and view the help.
Among them, we can see
Insert picture description here
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.

Insert picture description here
No problem, compile and install

make && make install

Insert picture description here
Insert picture description here
Prompt us to drop the zilb package, and we will
Insert picture description here
compile and install again next time:
Insert picture description here
success.
Insert picture description here
But still can not use python3 command, only python2.7:
Insert picture description here
we need to enter the bin directory to execute the name command.
we need

For ease of use, let's link it to environment variables.

ln -s /usr/local/python3/bin/* /usr/local/bin

Insert picture description here
You can use the python3 command

Simple usage of Python code

Python scripts all end with py.

Write the first script:
Insert picture description here
use python2 to execute:
Insert picture description here
two ways are possible.
Use python3 to execute:
Insert picture description here
the second syntax is not supported, which is the difference between the 2 and 3 versions.
Insert picture description here
Insert picture description here
2 does not support Chinese, 3 supports Chinese. The
code begins to add:
Insert picture description here
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:
Insert picture description here
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:
Insert picture description here
input can only recognize numeric values, not letters, so an error is reported.
We want to make it possible to report errors:
Insert picture description here
raw_input can convert the input content to a string for processing.

Insert picture description here
When we use raw_input to define a variable, we can see that its type is a string.
Insert picture description here
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
Insert picture description here
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
Insert picture description here
Insert picture description here
Insert picture description here
The sequence of the contents in% behind must be consistent with the previous, otherwise Different types will report errors.
Insert picture description here
% f stands for floating point number.
Insert picture description here
When money is an integer, it will automatically fill in several 0s. .2 represents 2 0s.

Insert picture description here
Integers can also be filled, 1 is not enough for three, so it is 001.

Insert picture description here
%% means%
scale * 100 = 0.1 * 100 = 10

Published 50 original articles · Liked 18 · Visits 3780

Guess you like

Origin blog.csdn.net/thermal_life/article/details/105454577