#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: zhaosj
if None:
print("Hello")
#执行结果:
![]()
None 为 False,所以没有任何输出
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: zhaosj
for i in [1, 0]:
print(i+1)

Python 中,for 和 while 可以有 else 语句?
for 和 while 都可以有 else 语句
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: zhaosj
while 4 == 4:
print('4')

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
迭代输出序列时(如:列表)使用 for 比 while 更好?

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: zhaosj
for char in 'PYTHON STRING':
if char == ' ':
break
print(char, end='')
if char == 'O':
continue

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
本文深入探讨了Python编程的基础概念,包括条件判断、循环结构、序列迭代以及for和while语句的使用技巧。通过实例演示了如何在Python中处理None值,展示了for和while循环的不同应用场景,并解释了在迭代输出序列时推荐使用for循环的原因。
1066

被折叠的 条评论
为什么被折叠?



