无限循环

如果条件判断语句永远为 true,循环将会无限的执行下去,如下实例:

实例

#!/usr/bin/python # -*- coding: UTF-8 -*- var = 1 while var == 1 : # 该条件永远为true,循环将无限执行下去 num = raw_input("Enter a number :") print "You entered: ", num print "Good bye!"

以上实例输出结果:

Enter a number  :20
You entered: 20
Enter a number :29
You entered: 29
Enter a number :3
You entered: 3
Enter a number between :Traceback (most recent call last):
File "test.py", line 5, in <module>
num = raw_input("Enter a number :")
KeyboardInterrupt

注意:以上的无限循环你可以使用 CTRL+C 来中断循环。


循环使用 else 语句

在 python 中,while … else 在循环条件为 false 时执行 else 语句块:

实例

#!/usr/bin/python

count = 0
while count < 5:
print count, " is less than 5"
count = count + 1
else:
print count, " is not less than 5"

以上实例输出结果为:

0 is less than 5
1 is less than 5
2 is less than 5
3 is less than 5
4 is less than 5
5 is not less than 5


简单语句组

类似 if 语句的语法,如果你的 while 循环体中只有一条语句,你可以将该语句与while写在同一行中, 如下所示:

实例

#!/usr/bin/python

flag = 1

while (flag): print 'Given flag is really true!'

print "Good bye!"

python36的更多相关文章

  1. Python36 二进制文件读写问题

    在Python36中写如下代码: __author__ = '-------'#-*- coding: utf-8 -*-import struct fo = open("myfile.tx ...

  2. centos 安装 python36

    centos6 安装 python36 临时方法: https://www.softwarecollections.org/en/scls/rhscl/rh-python36/ 方法二: http:/ ...

  3. 【Selenium】【BugList4】执行pip报错:Fatal error in launcher: Unable to create process using '""D:\Program Files\Python36\python.exe"" "D:\Program Files\Python36\Scripts\pip.exe" '

    环境信息: python版本:V3.6.4 安装路径:D:\Program Files\python36 环境变量PATH:D:\Program Files\Python36;D:\Program F ...

  4. python(1)在windows8.1下搭建python27和python36环境

    去Python官网下载需要的Python版本 https://www.python.org/ 我下载的是下面这两个版本: Python 2.7.13 Python 3.6.1 安装Python27时, ...

  5. windows7+cuda8+cudnn6+python36+tensorflow_gpu1.4配置

    下载文件 cuda8,自行网上下载online的安装包就好了 cudnn6 python36 tensorflow_gpu 下载地址:https://pan.baidu.com/s/1mjwOi5E ...

  6. Python36和Python27共存的方法

    Python26和Python37环境的配置 设置环境变量 我的电脑右键属性-高级系统属性-环境变量 选择系统变量中的Path,双击打开 加入你的Python安装路径 C:\Python27;C:\P ...

  7. pip安装lxml报错 Fatal error in launcher: Unable to create process using '"c:\users\administrator\appdata\local\programs\python\python36\python.exe" "C:\Users\Administrator\AppData\L

    pip install lxml 安装报错 E:\apollo\spider_code>Fatal error in launcher: Unable to create process usi ...

  8. RuntimeError: Failed to init API, possibly an invalid tessdata path: E:\python36\报错

    OCR:光学识别符,tesserocr是python中一个OCR识别库,是对tesseract做的一个python的 API封装,所以它的核心是tesseract 在这里我安装的版本是:tessera ...

  9. 通过离线安装包解决了 from cryptography.hazmat.bindings._openssl import ffi, lib ImportError: /usr/local/python36/lib/python3.6/site-packages/cryptography-2.2.2-py3.6-linux-x86_64.egg/cryptography/hazmat/binding

    场景:内网服务器不能上外网(代理也不通!), 之前安装了PYTHON的几个安装包,但不是知道为什么无法使用PARAMIKO这个模块 在导入 from cryptography.hazmat.bindi ...

  10. ()centos7 安装python36

    centos7 默认安装 python2.7 1.先安装python36和对应pip yum install python-pip #安装python2的pip yum install python3 ...

随机推荐

  1. Roadblocks

    poj3255 题目: Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best ...

  2. .Net NPOI 简单Demo,一看就会

    #region   文件输出 public class BasicInfodsa { public string name; public string phone; } List zyData = ...

  3. .net 定时任务(调度 .net quartz) demo

    详细解说:https://blog.csdn.net/noaman_wgs/article/details/80984873 demo如下: 新建控制台应用程式: 添加Nuget包 static vo ...

  4. PostgreSQL事务隔离级别

    一.概念 并发控制是多个事务在并发运行时,数据库保证事务一致性(Consistency)和隔离性(Isolation)的一种机制.PostgreSQL使用了多版本并发控制技术的一种变体:快照隔离San ...

  5. jquery获得标签的值或元素的内容

    例如: .html() 获取a标签中的i元素 console.error($("a[name=" + index + "]").html()); 设置a标签里的 ...

  6. Linux操作命令(一)1.ls命令 2.cd命令 3.pwd命令

    1.ls 命令 ls 命令就是 list 的缩写, ls 用来打印出当前目录的清单. 参数 描述 -a –all 列出目录下的所有文件,包括以 . 开头的隐含文件 -l 除了文件名之外,还将文件的权限 ...

  7. 魔兽世界2009年更换代理,九城CEO至全体员工公开信

    尊敬的全体第九城市员工, 最近一段时间以来,有关九城将要失去<魔兽世界>代理权的说法甚嚣尘上,各种传言四起.在目前来自<魔兽世界>的收入仍占九城收入绝大部分的情况下,对于外界的 ...

  8. zabbix-agent2安装问题汇总

    1.yum源报错 # 具体报错信息 failure: repodata/4bb73bd0742c638c3cd1e73a5f3dc8838c7b0d693c9f50b7ed8266c3e83308d3 ...

  9. 第一天 python环境变量安装(2.7)

    一.什么是python Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计简单,易学,免费,开源,面向对象,可拓展性 Python 是一种解释型语言: ...

  10. Django,Flask中的request

    request的结构获取 class Upload(Resource): def post(self): print(curPath) print(request.files['file'].__di ...