项目详情
由分享
HelloGitHub 评分
0 人评分
开源•MIT
认领
讨论
收藏
分享
16.4k
星数
是
中文
Python
主语言
否
活跃
15
贡献者
25
Issues
否
组织
无
最新版本
3k
Forks
MIT
协议
更多
一份以代码和注释方式讲解 Python 的免费教程。每个 Python 基础语法和知识点都采用可以运行的代码为例讲解,再配上适当的注释和参考资料,让你快速上手 Python。此项目不仅可以当做学习 Python 的资料,还可以留着做为速查表
```python
"""WHILE statement
@see: https://docs.python.org/3/tutorial/controlflow.html
@see: https://docs.python.org/3/reference/compound_stmts.html#the-while-statement
The while loop executes as long as the condition remains true. In Python, like in C, any
non-zero integer value is true; zero is false. The condition may also be a string or list
value, in fact any sequence; anything with a non-zero length is true, empty sequences are
false.
The test used in the example is a simple comparison. The standard comparison operators are
written the same as in C: < (less than), > (greater than), == (equal to), <= (less than or
equal to), >= (greater than or equal to) and != (not equal to).
"""
def test_while_statement():
"""WHILE statement"""
# Let's raise the number to certain power using while loop.
number = 2
power = 5
result = 1
while power > 0:
result *= number
power -= 1
# 2^5 = 32
assert result == 32
```
评论
评分:
暂无精选评论