python installation and environment configurationPython interpreter installation under Windows
Open official website https://www.python.org/downloads/windows/Download Center
Test whether the installation was successful
Windows-to-run input cmd, then enter, pop-up cmd program, enter Python, if you can enter the interactive environment, represents the successful installation.
Python interpreter installation under Linux
无需安装,原装Python环境
ps:如果自带
2.6
,请更新至
2.7
Update Python
Unloading load can be
Linux:
Linux Yum relies on its own python, to prevent errors, the update here is actually to install a python
查看默认Python版本
python
-
V
1
、安装gcc,用于编译Python源码
yum install gcc
2
、下载源码包,https:
/
/
www.python.org
/
ftp
/
python
/
3
、解压并进入源码文件
4
、编译安装
.
/
configure
make
all
make install
5
、查看版本
/
usr
/
local
/
bin
/
python2.
7
-
V
6
、修改默认Python版本
mv
/
usr
/
bin
/
python
/
usr
/
bin
/
python2.
6
ln
-
s
/
usr
/
local
/
bin
/
python2.
7
/
usr
/
bin
/
python
7
、防止yum执行异常,修改yum使用的Python版本
vi
/
usr
/
bin
/
yum
将头部
#!/usr/bin/python 修改为 #!/usr/bin/python2.6Variable what is a variable?
Name=' Egon 'age =18
View CodeWhy do we have variables?
The essence of program execution is a series of state changes, the core of the variable two words is changed, one is the amount, ' change ' just corresponds to the program changes, ' quantity ' is measured, reflects a certain state,
Like a character in a game. Initial level: Level=1, after a period of time to upgrade: level=10
Declaration of a variable
Name = "Alex Li"
A reference to a variable
#!/usr/bin/env pythonname= ' Egon ' #变量的声明name #通过变量名, the value of the reference variable print (name) #引用并且打印变量名name对应的值, i.e. ' Egon '
Assignment/modification of variables
#!/usr/bin/env pythonname1= ' LHF ' name2= ' Egon '
#!/usr/bin/env pythonname1= ' LHF ' name2=name1
#!/usr/bin/env python# A game character from level 1 to Level 2 level=1level=2# a game account password changed from ' 123 ' to ' 456 ' passwd= ' 123 ' passwd= ' 456 ' #一个人的名字有 ' LHF ' Change to ' Egon ' name= ' LHF ' name= ' Egon '
Read user input (5-8 min)
Name = input ("What is your name?") Print ("Hello" + name)
Executing the script will find that the program waits for you to enter your name and then continue to go down.
Allows the user to enter multiple information, as follows
Name = input ("What is your name?") Age = Input ("What old is You?") Hometown = input ("Where is your hometown?") Print ("Hello", Name, "Your is", age, "years old, you came from", hometown)
Execution output
What is your name? Alex lihow old was You?22where is your hometown? Shandonghello Alex Li Your is years old and you came from Shandong
1 Python3 Unity is input,python2 in the raw_input equivalent to the Python3 input, in addition Python2 also have input2 31.res=input ("Python3:")4 52.res=raw_input ("Python2:")6 73.res=raw_input ("Python2:")8 91, 2 is saved as a string to the res regardless of which input is received, while 3 means that the type to which the user enters assigns a value to the ResTen One #!/usr/bin/env python A -Name=input ('Please enter user name:') - Print(name) the Execution - -C:\users\administrator>python D:\python_test\hello.py - Please enter your user name: Egon +Egonthe difference between input and raw_input
First: A beginner's knowledge of Python