程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Getting started with Python - Overview

編輯:Python

Python introduction - Summary

Python  Is a lightweight scripting language

characteristic :

  • pronunciation 【paisong】
  • python  English is Python , Giant snake means .
  • By the Dutch Guido van Rossum First invented .
  • Perl, PHP, Python  Collectively known as P Language .
  • And other languages {...} as well as begin ... end Compared to the code block of ,Python Space indentation is used to distinguish code blocks .
  • and Ruby equally , Integers (int) character string (str) And so on are treated as objects .

install :

◆ 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 Source code installation

CentOS 7.0 に Python 2.7.9  install

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 Operation method

◆ Windows

Global variables Path  Specify the directory in .Windows Next ,[ Control panel ]-[ System ]-[ Detailed system settings ]-[ environment variable ] Add in python.exe Directory of ( for example : C:\Python27).

DOS command

C:\>set
Path=C:\WINDOWS\system32;C:\WINDOWS;...( A little )...;C:\Python27
C:\>python -V
Python 2.7.9
C:\>type hello.py
print "Hello world!"
C:\>python hello.py
Hello world!
C:\>

◆ Linux

environment variable PATH Add in python File directory ( for example :/usr/local/python/bin). If it is installed again /usr/bin Next , No need to specify PATH Of .

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!
$ dialogue 

Dialogue mode

Python With dialogue mode .

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 end
Enter... In conversation mode help(), You can view various help information .

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.

About Python 3

2008 year Python 3.0 appear 、Python 2.x There is no complete compatibility 、 Now? Python 2 More people use it . And Python 2 The main differences are as follows .

  • print The command becomes a function . stay Python 2 in , Can be written as print "..." The format of , stay 3.0 In order to print("..."). stay Python 2 It can also be written as  print("...") In the form of . But if print Enter the following words ,print("AAA", "BBB") , The result is 「("AAA", "BBB")」.
  • Python 2 in ,"..." Represents a byte type character 、u"..."  representative Unicode character string , stay Python 3.0~3.2 in ,"..." The default is Unicode character string ,b"..." Is a byte type string , Input u"..." Will be submitted to the (SyntaxError abnormal ). however Python 3.3 after u"..." The writing method of "s" has been restored ,"..." Also as a Unicode String to handle .
  • Integers int  and long  Unified as int type . Maybe there will be a difference in performance , however 32bit perhaps 64bit  Long integer , Without losing accuracy .123L Medium L Writing will lead to (SyntaxError abnormal ),sys.maxint It will also show (AttributeError abnormal ).

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved