iwanghang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

https://www.python.org/

功能定义

可扩展编程的核心是定义函数。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 knows the usual control flow statements that other languages speak — ifforwhile and range — with some of its own twists, of course. More control flow tools in Python 3

Python知道通常的控制流语句其他语言说话- ifforwhile and 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


Python是一种编程语言,可以让你快速工作并更有效地整合系统。学到更多

开始使用

无论您是编程新手还是有经验的开发人员,学习和使用Python都很容易。

从我们的初学者指南开始

 
posted on 2018-01-10 14:06  iwanghang  阅读(260)  评论(0编辑  收藏  举报