成功案例
>>> 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 程式設計師社群的發展。瞭解更多