課程參考資源
Python文檔
https://www.python.org/doc/
Python發布下載
https://www.python.org/downloads/
初學者Python指南
https://www.python.org/about/gettingstarted/
Python Wiki初學者指南
https://wiki.python.org/moin/BeginnersGuide
第一步
功能定義
可擴展編程的核心是定義函數。 Python允許使用強制和可選參數,關鍵字參數,甚至任意參數列表。 有關在Python 3中定義函數的更多信息
# 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概述。
# Python 3: Simple output (with Unicode)
>>> print("Hello, I'm Python!")
Hello, I'm Python!
# Input, assignment
>>> name = input('What is your name?n')
>>> print('Hi, %s.' % name)
What is your name?
Python
Hi, Python.
您所期望的所有流程
Python知道其他語言會說的通常的控制流語句- if
, for
, while
和 range
-當然有一些曲折。 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: 384
下載 EITC/CP/PPF Python 程式設計基礎課程的完整離線自學準備資料(PDF 檔案)