![]() | |
編程範式 | 多範型:函數式、指令式、反射式、結構化、物件導向 |
---|---|
設計者 | Guido van Rossum |
編程員 | Python軟件基金會 |
第一次出現 | 1991年[1] |
穩定版本 | 3.12.3[2] ![]() |
類型系統 | 鴨子類型、動態、強類型[3]、漸進(自從3.5)[4] |
操作系統 | 跨平臺:Windows、Linux/Unix、macOS等 |
軟件授權 | Python軟件基金會許可證 |
副檔名 | .py、.pyi、.pyc、.pyd、.pyo(3.5之前)[5]、Template:Notatypo、.pyz(自從3.5)[6] |
網站 | www![]() |
Major implementations | |
CPython、PyPy、IronPython、Jython、Stackless Python、MicroPython、CircuitPython、RustPython[7] | |
Dialects | |
Cython、RPython、Starlark[8] | |
啟發語言 | |
ABC[9]、Ada[10]、ALGOL 68[11]、APL[12]、C[13]、C++[14]、CLU[15]、Dylan[16]、Haskell[17]、Icon[18]、Java[19]、Lisp[20]、Modula-3[14]、Perl、Standard ML[12] | |
影響語言 | |
Boo、Cobra、CoffeeScript[21]、D、F#、Falcon、Genie[22]、Go、Groovy、JavaScript[23][24]、Julia[25]、Nim、Ring[26]、Ruby[27]、Swift[28] | |
Python(英國發音:/ˈpaɪθən/ 美國發音:/ˈpaɪθɑːn/),係一種直譯高階程式語言,由荷蘭科研機構 CWI(數學及電腦科學中心)嘅 Guido van Rossum 設計,1991年首次推出[29][30],特徵係啲編碼嘅可讀性高、空格有語義(所謂越位法則)、支援多種嘅編程範式(包括結構化編程同物件導向編程)、而且有個全面嘅標準庫[31]。因為呢啲緣故,Python 喺廿一世紀初俾人廣泛採用嚟做好多種唔同嘅編程作業,例如係編寫機械學習程式同電子遊戲程式[32]。喺工程學同科學界常用;喺財經界亦都成為咗考CFA牌可以考嘅嘢[33]。
Python 呢種程式語言跟越位法則(off-side rule),即係話縮進會用嚟表示「邊幾行碼屬同一個碼塊」嘅資訊。
Python 有35個關鍵字(又叫保留字,即係唔可以當識別碼用):
and
as
assert
async
await
break
class
continue
def
del
elif
else
except
False
finally
for
from
global
if
import
in
is
lambda
None
nonlocal
not
or
pass
raise
return
True
try
while
with
yield
array[::]
zip(,)
Python 容許多種控制流程功能,包括:
if... else
if...elif...else
for
while
try
print(...)
input("")
with open("...", " ") as ...
def func1(*args):
+
相加-
相減*
相乘/
除%
取餘數以下係 Python 嘅 Hello World 代碼,出名在非常簡單:
print("Hello, world!")
以下呢段 python 碼會攞一個正整數做 input
,再俾嗰個數嘅階乘做 output
:
n = int(input('Type a number, and its factorial will be printed: '))
if n < 0:
raise ValueError('You must enter a positive integer')
fact = 1
i = 2
while i <= n:
fact *= i
i += 1
print(fact)
<ref>
標籤;無文字提供畀叫做faq-created
嘅參照even though the design of C is far from ideal, its influence on Python is considerable.
((cite journal))
: Check |url=
value (help)
It is a mixture of the class mechanisms found in C++ and Modula-3
replace "CLU" with "Python", "record" with "instance", and "procedure" with "function or method", and you get a pretty accurate description of Python's object model.
The C3 method itself has nothing to do with Python, since it was invented by people working on Dylan and it is described in a paper intended for lispers
((cite web))
: Check |url=
value (help)CS1 maint: url-status (link)
((cite web))
: no-break space character in |title=
at position 8 (help)
((cite web))
: Check |url=
value (help); no-break space character in |title=
at position 8 (help)
<ref>
標籤;無文字提供畀叫做Julia
嘅參照The Swift la nguage is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.