Python continue语句用法实例_python

Python使用 continue 语句跳出循环,而break跳出整个循环。continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮循环。continue语句使用在用在while和for循环中。

一、Python 语言 continue 语句语法格式如下:

复制代码 代码如下:

continue

二、逻辑流程图:

三、使用实例:

复制代码 代码如下:

#!/usr/bin/python

for letter in 'Python':     # First Example
   if letter == 'h':
      continue
   print 'Current Letter :', letter

var = 10                    # Second Example
while var > 0:             
   var = var -1
   if var == 5:
      continue
   print 'Current variable value :', var
print "Good bye!"

以上实例执行结果:

复制代码 代码如下:

Current Letter : P
Current Letter : y
Current Letter : t
Current Letter : o
Current Letter : n
Current variable value : 9
Current variable value : 8
Current variable value : 7
Current variable value : 6
Current variable value : 4
Current variable value : 3
Current variable value : 2
Current variable value : 1
Current variable value : 0
Good bye!

时间: 2024-08-02 20:52:01

Python continue语句用法实例_python的相关文章

python中list循环语句用法实例_python

本文实例讲述了python中list循环语句用法.分享给大家供大家参考.具体用法分析如下: Python 的强大特性之一就是其对 list 的解析,它提供一种紧凑的方法,可以通过对 list 中的每个元素应用一个函数,从而将一个 list 映射为另一个 list. 实例 复制代码 代码如下: a = ['cat', 'window', 'defenestrate'] for x in a:      print x, len(x) for x in [1, 2, 3]: print x,    

python中反射用法实例_python

本文实例讲述了python中反射用法.分享给大家供大家参考.具体如下: import sys, types,new def _get_mod(modulePath): try: aMod = sys.modules[modulePath] if not isinstance(aMod, types.ModuleType): raise KeyError except KeyError: # The last [''] is very important! aMod = __import__(mo

Python sys.argv用法实例

  这篇文章主要介绍了Python sys.argv用法实例,sys.argv[]是用来获取命令行参数的,sys.argv[0]表示代码本身文件路径,其它则用来表示获取输入参数,需要的朋友可以参考下 sys.argv变量是一个字符串的列表.特别地,sys.argv包含了命令行参数 的列表,即使用命令行传递给你的程序的参数. 这里,当我们执行python using_sys.py we are arguments的时候,我们使用python命令运行using_sys.py模块,后面跟着的内容被作为

python中as用法实例分析

  这篇文章主要介绍了python中as用法,实例分析了as的功能及相关使用技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了python中as用法.分享给大家供大家参考.具体分析如下: ? 1 import some # some 为一个模组 如果想要改变被导入模组在当前模组中的名称,而不是sys.modules中的名称.可以使用import as,例如: ? 1 2 import some as other print(other.name) 和 ? 1 2 3 4 import

Javascript中With语句用法实例_javascript技巧

本文实例讲述了Javascript中With语句用法.分享给大家供大家参考.具体如下: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>With语句(类似于VB中的)</title>

python中pass语句用法实例分析

  这篇文章主要介绍了python中pass语句用法,对比C++程序实例分析了pass语句的使用方法,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了python中pass语句用法.分享给大家供大家参考.具体分析如下: 1.空语句 do nothing 2.保证格式完整 3.保证语义完整 4.以if语句为例: C/C++中写法: ? 1 2 3 4 if(true) ; // do nothing else {} // do nothing python中写法: ? 1 2 3 4 i

python正则表达式match和search用法实例_python

本文实例讲述了python正则表达式match和search用法.分享给大家供大家参考.具体分析如下: python提供了2中主要的正则表达式操作:re.match 和 re.search. match :只从字符串的开始与正则表达式匹配,匹配成功返回matchobject,否则返回none: search :将字符串的所有字串尝试与正则表达式匹配,如果所有的字串都没有匹配成功,返回none,否则返回matchobject:(re.search相当于perl中的默认行为) import re d

python中bisect模块用法实例_python

本文实例讲述了python中bisect模块用法,分享给大家供大家参考. 具体方法分析如下: 这个模块只有几个函数,一旦决定使用二分搜索时,立马要想到使用这个模块. 示例代码如下: import bisect L = [1,3,3,6,8,12,15] x = 3 x_insert_point = bisect.bisect_left(L,x)#在L中查找x,x存在时返回x左侧的位置,x不存在返回应该插入的位置..这是3存在于列表中,返回左侧位置1 print x_insert_point x_

python中sets模块的用法实例_python

本文实例简单讲述了python中sets模块的用法,分享给大家供大家参考. 具体方法如下: import sets magic_chars = sets.Set('abracadabra') print magic_chars poping_chars = sets.Set('supercalifragilisticeexpialidocious') print poping_chars print "".join(magic_chars & poping_chars) 程序运