Python
From Wikipedia, the free encyclopedia
Remove ads
Python(英國發音:/ˈpaɪθən/ 美國發音:/ˈpaɪθɑːn/),係一種直譯高階程式語言,由荷蘭科研機構 CWI(數學及電腦科學中心)嘅 Guido van Rossum 設計,1991年首次推出[29][30],特徵係啲編碼嘅可讀性高、空格有語義(所謂越位法則)、支援多種嘅編程範式(包括結構化編程同物件導向編程)、而且有個全面嘅標準庫[31]。因為呢啲緣故,Python 喺廿一世紀初俾人廣泛採用嚟做好多種唔同嘅編程作業,例如係編寫機械學習程式同電子遊戲程式[32]。喺工程學同科學界常用;喺財經界亦都成為咗考CFA牌可以考嘅嘢[33]。
Remove ads
語法
縮進
Python 呢種程式語言跟越位法則(off-side rule),即係話縮進會用嚟表示「邊幾行碼屬同一個碼塊」嘅資訊。
關鍵字
Python 有35個關鍵字(又叫保留字,即係唔可以當識別碼用):
andasassertasyncawaitbreakclasscontinuedefdelelifelseexceptFalsefinallyforfromglobalifimportinislambdaNonenonlocalnotorpassraisereturnTruetrywhilewithyield
數據結構
array[::]zip(,)
控制流程
Python 容許多種控制流程功能,包括:
if... elseif...elif...elseforwhiletry
I/O
print(...)input("")with open("...", " ") as ...
子程序
def func1(*args):
運算子
+相加-相減*相乘/除%取餘數
Remove ads
例子碼
以下係 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)
睇埋
攷
參考
Wikiwand - on
Seamless Wikipedia browsing. On steroids.
Remove ads
