Python 是一種輕量的腳本型語言
特點:
安裝:
◆ Windows
http://www.python.org/
◆ Linux(Red Hat / CentOS)
Linux
# Python 2.7
$ sudo yum install -y python
# Python 3.6 (from EPEL)
$ sudo yum install -y epel-release
$ sudo yum install python36
# Python 3.6 (from IUS)
$ sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
$ sudo yum install -y python36u
◆ Linux(Ubuntu / Debian)
Linux
$ sudo apt-get install python2.7
◆ Linux源代碼安裝
CentOS 7.0 に Python 2.7.9 安裝
Linux
# yum -y install wget gcc zlib-devel gdbm-devel readline-devel
# yum -y install sqlite-devel openssl-devel tk-devel bzip2-devel
$ wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
$ tar zxvf Python-2.7.9.tgz
$ cd Python-2.7.9
$ ./configure --with-threads --enable-shared --prefix=/usr/local
$ make
$ sudo make altinstall
Python運行方法
◆ Windows
全局變量 Path 裡指定目錄。Windows下,[控制面板]-[系統]-[系統詳細設定]-[環境變量]裡加入python.exe的所在目錄(例如: C:\Python27)。
DOS命令
C:\>set
Path=C:\WINDOWS\system32;C:\WINDOWS;...(略)...;C:\Python27
C:\>python -V
Python 2.7.9
C:\>type hello.py
print "Hello world!"
C:\>python hello.py
Hello world!
C:\>
◆ Linux
環境變量PATH裡加入 python文件的目錄(例如:/usr/local/python/bin)。如果安裝再/usr/bin下,是不需要指定PATH的。
Linux
$ export PATH=$PATH:/usr/local/python/bin
$ python -V
Python 2.7.9
$ cat hello.py
print "Hello world!"
$ python hello.py
Hello world!
$對話
對話模式
Python具有對話模式。
Linux
$ python
Python 2.7.9 (default, Dec 26 2014, 02:00:03)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 5+8
13
>>> 'Hello world!'
'Hello world!'
>>> a = 5
>>> b = 8
>>> a + b
13
>>> # Linux:Ctrl-D, Windows:Ctrl-Z Enter結束
對話模式下輸入help(),可以查看到各種幫助信息。
Linux
$ python
>>> help()
Welcome to Python 2.7! This is the online help utility.
:
>>> import sys
>>> help(sys)
Help on built-in module sys:
NAME
sys
FILE
(built-in)
MODULE DOCS
http://docs.python.org/library/sys
DESCRIPTION
This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.
關於Python 3
2008年Python 3.0出現、Python 2.x沒有完整的兼容性、現在Python 2使用的人比較多。與Python 2不同的點主要有以下幾點。