
课程参考资源
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