专业编程基础技术教程

网站首页 > 基础教程 正文

朝文分享(13):Python入门指南(三)——if语句篇

ccvgpt 2024-07-20 11:50:23 基础教程 7 ℃

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是LearningYard新学苑。

朝文分享(13):Python入门指南(三)——if语句篇

今天小编为大家带来“Python入门指南”,欢迎您的访问。

Share interest, spread happiness, increase knowledge, and leave beautiful.

Dear, this is the LearingYard Academy!

Today, the editor brings the Getting Started with Python,welcome to visit!



一、if语句

if语句表如果,如果满足某某条件,则执行后面得代码。格式为“ if 条件: ”。需要注意的是,满足条件后执行的代码是if语句下面缩进的代码,没有缩进的代码不在if语句的体系内,无论满不满足都会执行。

if statement table If, if a condition is met, the following code is executed. The format is "if condition:". It should be noted that the code executed after meeting the conditions is the indented code under the if statement, and the code without indented is not in the if statement system, and will be executed regardless of whether it is satisfied.

二、if else语句

相比单独的if,if else提供了不满足条件后的选择。Else语句的格式为 “else:”。延续前面的程序,在整个if语句后加上else语句,在年龄不满足大于等于18的时候,输出else内的程序。

Compared to if alone, if else provides a choice if the condition is not satisfied. The format of the Else statement is "else:". Continue the previous program, add else statements after the entire if statement, and output else programs when the age is not greater than or equal to 18.

三、if elif else语句

if elif else语句又比之前多了一个elif,else if的缩写。Elif语句格式与if语句差不多,“elif 条件: ”。elif可以多次出现,但一定在if和else中间。

The if elif else statement has one more elif, short for else if. The format of the Elif statement is similar to the if statement, "elif condition:". elif can occur multiple times, but it must be somewhere between if and else.




今天的分享就到这里了,

如果您对文章有独特的想法,

欢迎给我们留言。

让我们相约明天,

祝您今天过得开心快乐!

That's all for today's sharing.

If you have a unique idea about the article,

please leave us a message,

and let us meet tomorrow.

I wish you a nice day!

参考资料

翻译:网易有道翻译

本文由LearningYard学苑整理并发出,如有侵权请后台留言沟通.

文案|Dongyang

排版|Dongyang

审核|hong

Learning Yard 新学苑

Tags:

最近发表
标签列表