开发者社区> 问答> 正文

python怎么写死循环语句

python怎么写死循环语句

展开
收起
云计算小粉 2018-05-10 20:11:03 2070 0
2 条回答
写回答
取消 提交回答
  • image.png

    标准死循环,cpu跑满

    2019-11-26 15:23:50
    赞同 展开评论 打赏
  • while 循环

    numbers=[1,2,4,6,7,8,12]
    enent=[]
    odd=[]
    while len(numbers) > 0:

    number=numbers.pop()
    if(number % 2 == 0):
        enent.append(number)
        print number, '是偶数'
        print numbers
    
    else:
        odd.append(number)
        print number,'不是偶数'

    print enent
    print odd

    continue 和 break 用法

    continue 用于跳过该次循环,

    break 则是用于退出循环,

    此外"判断条件"还可以是个常值,表示循环必定成立

    i = 1
    while i < 10:

    i += 1
    if i % 2 > 0:  # 非双数时跳过输出
        continue
    print i  # 输出双数2、4、6、8、10
    

    i = 1
    while True: # 循环条件为1必定成立

    print i  # 输出1~10
    i += 1
    if i > 11:  # 当i大于10时跳出循环
    2019-07-17 22:25:02
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载