【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)
相关推荐
筵陌3 分钟前
算法:动态规划
算法·动态规划
大江东去浪淘尽千古风流人物4 分钟前
【DSP】xiBoxFilter_3x3_U8 dsp VS cmodel
linux·运维·人工智能·算法·vr
长行22 分钟前
Python|Windows 安装 DeepSpeed 安装方法及报错 Unable to pre-compile async_io 处理
windows·python·deepspeed
百锦再22 分钟前
python之路并不一马平川:带你踩坑Pandas
开发语言·python·pandas·pip·requests·tools·mircro
Python之栈22 分钟前
5款拖拽式Python GUI生成器助你快速打造炫酷界面
python
todoitbo23 分钟前
多模数据库技术解析:以KingbaseES MongoDB兼容版为例
数据库·mongodb·kingbasees·金仓数据库
灏瀚星空23 分钟前
基于 Python 与 GitHub,打造个人专属本地化思维导图工具全流程方案(上)
开发语言·人工智能·经验分享·笔记·python·个人开发·visual studio
用什么都重名23 分钟前
「实战指南」使用 Python 调用大模型(LLM)
python·大模型·llm·api调用
是Dream呀23 分钟前
Python从0到100(一百):基于Transformer的时序数据建模与实现详解
开发语言·python·transformer
资源存储库24 分钟前
【笔记】如何修改一个conda环境的python版本?
笔记·python·conda