2022年 11月 4日

01.Python主页

https://www.python.org/

功能定义

可扩展编程的核心是定义函数。Python允许强制参数和可选参数,关键字参数,甚至任意参数列表。更多关于在Python 3中定义函数的信息

  1. # Python 3: Fibonacci series up to n
  2. >>> def fib(n):
  3. >>> a, b = 0, 1
  4. >>> while a < n:
  5. >>> print(a, end=' ')
  6. >>> a, b = b, a+b
  7. >>> print()
  8. >>> fib(1000)
  9. 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

 

复合数据类型

列表(称为其他语言的数组)是Python可以理解的复合数据类型之一。可以使用其他内置函数对列表进行索引,切片和操作。更多关于Python 3中的列表

  1. # Python 3: List comprehensions
  2. >>> fruits = ['Banana', 'Apple', 'Lime']
  3. >>> loud_fruits = [fruit.upper() for fruit in fruits]
  4. >>> print(loud_fruits)
  5. ['BANANA', 'APPLE', 'LIME']
  6. # List and the enumerate function
  7. >>> list(enumerate(fruits))
  8. [(0, 'Banana'), (1, 'Apple'), (2, 'Lime')]
 

直观的解释

的计算是与Python简单,表达式语法是直接的:运营商+-*/按预期方式工作; 圆括号()可以用于分组。更多关于Python 3中简单的数学函数

  1. # Python 3: Simple arithmetic
  2. >>> 1 / 2
  3. 0.5
  4. >>> 2 ** 3
  5. 8
  6. >>> 17 / 3 # classic division returns a float
  7. 5.666666666666667 >>> 17 // 3 # floor division 5


快速和容易学习

有经验的任何其他语言的程序员都可以很快拿起Python,初学者可以找到易于学习的简洁的语法和缩进结构。通过我们的Python 3概述来满足您的胃口

  1. # Python 3: Simple output (with Unicode)
  2. >>> print("Hello, I'm Python!")
  3. Hello, I'm Python!
  4. # Input, assignment
  5. >>> name = input('What is your name?\n')
  6. >>> print('Hi, %s.' % name)
  7. What is your name?
  8. Python
  9. 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中更多的控制流工具

  1. # For loop on a list
  2. >>> numbers = [2, 4, 6, 8]
  3. >>> product = 1
  4. >>> for number in numbers:
  5. ... product = product * number
  6. ...
  7. >>> print('The product is:', product)
  8. The product is: 384


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

开始使用

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

从我们的初学者指南开始