python中没有明显的语句块标记,是通过缩进来识别语句块的。Python是一种跨平台的计算机程序设计语言;是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言;多被用于独立的、大型项目的开发。

python没有明显的语句块标记,是通过缩进来识别语句块的。
这里打开编辑器,新建一个py文件作为示范。
def happy():
print("Very Happy!")
happy()
创建函数的时候,冒号以后需要进行缩进,标记语句块。

x = 1 while x <p>在用while的时候,冒号以后需要进行缩进,标记语句块。</p><p><img src="https://img.php.cn/upload/image/370/365/424/1594783303828396.png?x-oss-process=image/resize,p_40" title="1594783303828396.png" alt="eb556ecab46dff69dc1403652fa8f87.png"></p><pre class="brush:php;toolbar:false">x = 1 if x <p>在用if和else语句的时候,冒号以后需要进行缩进,标记语句块。</p><div class="aritcle_card flexRow artxards"> <div class="artcardd flexRow"> <a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill9965" title="macOS UI 自动化技能包 —— 用 Python 控制你的 Mac"><img src="https://img.php.cn/upload/skill/001/246/273/6adaf20dbae7c507.jpg" alt="macOS UI 自动化技能包 —— 用 Python 控制你的 Mac" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a> <div class="aritcle_card_info flexColumn"> <a rel="nofollow" href="/xiazai/skill9965" title="macOS UI 自动化技能包 —— 用 Python 控制你的 Mac" class="overflowclass">macOS UI 自动化技能包 —— 用 Python 控制你的 Mac</a> <p class="overflowclass">让 macOS 自动化像说话一样简单 —— 用代码控制你的 Mac,无需学习 AppleScript 系统要求 macOS 14+ (Sonoma) Python 3.9+ 需要开启:辅助功能 + 屏幕录制权限</p> </div> <a rel="nofollow" href="/xiazai/skill9965" title="macOS UI 自动化技能包 —— 用 Python 控制你的 Mac" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a> </div> </div><p><img src="https://img.php.cn/upload/image/791/992/219/1594783333103357.png?x-oss-process=image/resize,p_40" title="1594783333103357.png" alt="6f279ae57c94d068fec596fa5d02111.png"></p><p>如果不用标记语句块,是会报错的。</p><p><img src="https://img.php.cn/upload/image/585/805/486/1594783357205468.png?x-oss-process=image/resize,p_40" title="1594783357205468.png" alt="973b6de7ec84533037828419ca8b352.png"></p><pre class="brush:php;toolbar:false">def hey(): x = 1 while x <p>每一次冒号以后都是需要标记语句块,而且要根据格式一层一层标记。</p><p><img src="https://img.php.cn/upload/image/825/327/274/1594783404816076.png?x-oss-process=image/resize,p_40" title="1594783404816076.png" alt="1ce5353f08331aa04bbed9da86f9de2.png"></p><p>推荐教程:《<a href="https://www.php.cn/course/list/30.html" target="_blank">python教程</a>》</p>
Python免费学习笔记(深入):立即使用
在学习笔记中,你将探索 Python 的核心概念和高级技巧!










