#!/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

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐