无限循环

如果条件判断语句永远为 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. java环境变量配置-最新版

    安装 百度"java下载"进入官网下载最新版,闭着眼睛安装: 配置jre 因java11以上不自带jre,需要我们自己配置,配置如下: # 终端进入jdk所在的目录后执行 bin\ ...

  2. 跳板攻击之: MSF 添加路由方式渗透内网

    跳板攻击之: MSF 添加路由方式渗透内网 目录 跳板攻击之: MSF 添加路由方式渗透内网 1 Metasploit 跳板攻击: 添加路由方式原理 2 实验环境 2.1 建立 meterpreter ...

  3. 代码随想录算法训练营day13

    基础知识 二叉树基础知识 二叉树多考察完全二叉树.满二叉树,可以分为链式存储和数组存储,父子兄弟访问方式也有所不同,遍历也分为了前中后序遍历和层次遍历 Java定义 public class Tree ...

  4. Xilinx XPM使用说明--XPM_MEMORY_SDPRAM

    XPM_MEMORY_SDPRAM 参数化宏:简单的双端口RAM 介绍 此宏用于实例化简单双端口RAM.端口A用于从存储器执行写入操作,端口B可用于从存储器读取. 下面介绍XPM_MEMORY实例的基 ...

  5. TIM PC版 v3.4.5.22071 绿色便携版

    修改历史: 2023.01.30:自改官方 3.4.5.22071 最新正式版本------------------------------------------------------------ ...

  6. python-异常/文件/时间/随机数

    python-异常/文件/时间/随机数 def exception_test(): try: x = float(input("请输入被除数:")) y = float(input ...

  7. sql两种表联查更新的方法

    1.update ceshi c1,ceshi2 c2 set c1.num=c2.aa where c1.id=c2.cid; 2.update ceshi c1 INNER JOIN ceshi2 ...

  8. foreach 和for

    "foreach和for循环如果只是遍历集合或者数组,用foreach好些,如果是对集合中的值进行修改,就要用for循环了,其实foreach的内部原理其实也是Iterator,但不能像It ...

  9. Java面向对象之什么是多态?

    多态 动态编译:类型:可扩展性 即同一方法可以根据发送对象的不同而采用多种不同的行为方式. 一个对象的实际类型是确定的,但可以指向对象的引用的类型有很多. 多态存在的条件: 1.有继承关系,类型转换异 ...

  10. 题解[LuoguP6222]「P6156简单题」加强版

    题解[LuoguP6222]「P6156简单题」加强版 加强版很好地体现了这个题的真正价值.(当然是指卡常 本题解给出了本题更详尽的推倒导和思考过程,思路与 CYJian 的类似,具体式子的个别地方换 ...