【Python操作基础】——while语句用法和pass语句

🍉CSDN小墨&晓末:https://blog.csdn.net/jd1813346972

个人介绍: 研一|统计学|干货分享
         擅长Python、Matlab、R等主流编程软件
         累计十余项国家级比赛奖项,参与研究经费10w、40w级横向

文章目录

  • [1 基本用法](#1 基本用法)
  • [2 While语句的注意事项](#2 While语句的注意事项)
  • [3 Pass语句含义](#3 Pass语句含义)
  • [4 Pass语句作用](#4 Pass语句作用)

【Python操作基础】系列------While语句用法,建议收藏!

该篇文章首先利用Python展示了使用While语句的基本用法以及其注意事项,同时展示了Pass语句的含义和作用。

1 基本用法

运行程序:

复制代码
i=1
sum=0
while(i<=100):
    sum=sum+i
    i+=1 
print(sum)

运行结果:

复制代码
5050

2 While语句的注意事项

from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all" ##执行多输出

i=1 sum=0 while(i<=10): sum=sum+i i+=1 if i6: continue if i9: break print(i,sum) else: print("here is else")

i=1 sum=0 while(i<=10): sum=sum+i i+=1 print(i,sum) else: print("here is else")

3 Pass语句含义

运行程序:

复制代码
a=10
b=11
if(a<=b):
                       #此处不能写空行
else:
    print(b)

4 Pass语句作用

运行程序:

复制代码
a=10
b=11
if(a<=b):
    pass                    #表示空语句
else:
    print(b)
相关推荐
靠沿14 小时前
【优选算法】专题十八——BFS解决拓扑排序问题
算法·宽度优先
Bdygsl14 小时前
MySQL(2)—— CRUD
数据库·mysql
cui_ruicheng14 小时前
C++数据结构进阶:哈希表实现
数据结构·c++·算法·哈希算法·散列表
qingcyb14 小时前
重复 id 对应的多个对象
开发语言·python
mingshili14 小时前
[python] asyncio常规操作记录
python·async
chushiyunen14 小时前
python edge-tts实现tts文本转语音、音频
数据库·python·音视频
原来是猿14 小时前
MySQL【事务中 - 事务的隔离级别】
数据库·mysql
嫂子的姐夫14 小时前
040-spiderbuf第C8题
javascript·爬虫·python·js逆向·逆向
li星野14 小时前
[特殊字符] 模拟试卷一:C++核心与系统基础(90分钟)答案版
开发语言·c++·算法
江上清风山间明月14 小时前
python将dtso文件转换成dtbo文件
python·dts·dtso