成功案例
>>> Python 軟體基金會
Python 軟體基金會的使命是推廣、保護並提升 Python 程式語言,並支援與促進多元化且國際化的 Python 程式設計師社群成長。了解更多
注意:雖然本網站不一定需要 JavaScript,但您的互動體驗將會受限。請開啟 JavaScript 以獲得完整體驗。
# Python 3: Fibonacci series up to n
>>> def fib(n):
>>> a, b = 0, 1
>>> while a < n:
>>> print(a, end=' ')
>>> a, b = b, a+b
>>> print()
>>> fib(1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987可擴充程式設計的核心在於定義函式。Python 允許使用必要參數、選擇性參數、關鍵字參數,甚至是任意參數列表。深入了解 Python 3 中的函式定義
# Python 3: List comprehensions
>>> fruits = ['Banana', 'Apple', 'Lime']
>>> loud_fruits = [fruit.upper() for fruit in fruits]
>>> print(loud_fruits)
['BANANA', 'APPLE', 'LIME']
# List and the enumerate function
>>> list(enumerate(fruits))
[(0, 'Banana'), (1, 'Apple'), (2, 'Lime')]列表(在其他語言中稱為陣列)是 Python 所能理解的複合資料型態之一。列表可以進行索引、切片,並透過其他內建函式進行操作。深入了解 Python 3 中的列表
# Python 3: Simple arithmetic
>>> 1 / 2
0.5
>>> 2 ** 3
8
>>> 17 / 3 # classic division returns a float
5.666666666666667
>>> 17 // 3 # floor division
5使用 Python 進行計算非常簡單,運算式語法也十分直觀:運算子 +、-、* 和 / 的運作符合預期;括號 () 可用於分組。深入了解 Python 3 中的簡易數學函式。
# For loop on a list
>>> numbers = [2, 4, 6, 8]
>>> product = 1
>>> for number in numbers:
... product = product * number
...
>>> print('The product is:', product)
The product is: 384Python 具備其他語言中常見的控制流程敘述 — if、for、while 和 range — 當然,它也有一些自己獨特的變化。更多 Python 3 中的控制流程工具
# Simple output (with Unicode)
>>> print("Hello, I'm Python!")
Hello, I'm Python!
# Input, assignment
>>> name = input('What is your name?\n')
What is your name?
Python
>>> print(f'Hi, {name}.')
Hi, Python.
任何其他語言的資深程式設計師都能快速上手 Python,而初學者則會發現其簡潔的語法和縮排結構非常容易學習。透過我們的 Python 3 概覽來開啟您的學習旅程。
Python 是一種讓您能快速工作並更有效地整合系統的程式語言。了解更多
Python 軟體基金會的使命是推廣、保護並提升 Python 程式語言,並支援與促進多元化且國際化的 Python 程式設計師社群成長。了解更多