Python Flow control[通俗易懂]

Python Flow control[通俗易懂]HowtotellPythontomakeintelligentdecisionsaboutwhatcodetorun,whatcodetoskip,andwhatcodetorepeatbasedonthevaluesithas.WithFlowcharts!Flowcontrolwillneedyesornooptionstomakedecisions.InPythoncode,yesandnoisshownas

大家好,又见面了,我是你们的朋友全栈君。

How to tell Python to make intelligent decisions about what code to run, what code to skip, and what code to repeat based on the values it has.With Flowcharts!

more sources:[Python Control Flow Statements and Loops]/
More Control Flow Tools

Flow control will need yes or no options to make decisions.In Python code,yes and no is shown as Boolean Values True and False.1.Boolean Values can be stored in variables and use as expressions.

Comparison Operators also called relational operators as below:

Equal to ==

Not equal to !=

Less than <

Greater than >

Less than or equal to <=

Greater than or equal to >=

When use comparison operators,an integer or floating-point value will always be unequal to a string value.That means 31!= ‘31’.Also The <, >, <=, and >=operators, on the other hand, work only with integer and floating-point values.Numbers! Never with string value.Computer will confuse if you did.
Don’t confuse with one equal side or two equal sides.
Two equal sides (equal to) asks whether 2 valus are the same with each other.(eg. True == True)

While one equal side is about puts value to the left side as variable. (Box in eg. Age = 7 )

The three Boolean operators are and, or, and not.

and,or always with 2 boolean values(experssions),considered as binary operators.
not only with one boolean value(experssion),considered as unary operator.
Python evaluates the not operators first, then the and operators, and then the or operators.

Flow control elements like conditions (like boolean values or expressions),blocks of code,program execution,flow control statements.(eg.if …: end with colon.or else:elif: while and for loops statement,continue and break statement.)

There are 3 rules of blocks of code:

Blocks begin when the indentation increases.

Blocks can contain other blocks.

Blocks end when the indentation decreases to zero or to a containing
block’s indentation.

Only use continue and break statements inside while and for loops.

For loops example as for i in range(3):

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/139580.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号