官术网_书友最值得收藏!

Understanding scripting flow logic

Flow control logic allows us to create dynamic operations by specifying different routes of program execution based upon a series of circumstances. In any script worth its salt, some manner of flow control is present. For example, flow logic would be required to create a dynamic script that returns different results based on options selected by the user. In Python, there are two basic sets of flow logic: conditionals and loops.

Flow operators are frequently accompanied by flow logic. These operators can be strung together to create more complicated logic. The following table represents a truth table and illustrates the value of various flow operators based on the A or B variable Boolean state:

The logical AND and OR operators are the third and fourth columns in the table. Both A and B must be True for the AND operator to return True. Only one of the variables needs to be True for the OR operator to be True. The not operator simply switches the Boolean value of the variable to its opposite (for example, True becomes False and vice versa).

Mastering conditionals and loops will take our scripts to another level. At its core, flow logic relies on only two values, True or False. As noted earlier, in Python, these are represented by the Boolean True and False data types.

主站蜘蛛池模板: 吕梁市| 平顶山市| 三明市| 峨眉山市| 象山县| 平和县| 沧州市| 西昌市| 南阳市| 米易县| 博湖县| 桃园市| 吉水县| 贵德县| 那坡县| 罗源县| 久治县| 城步| 招远市| 苍南县| 阿克| 沾化县| 尼勒克县| 治多县| 扶绥县| 泌阳县| 常州市| 左贡县| 黑龙江省| 蓬莱市| 扶绥县| 新干县| 临澧县| 获嘉县| 隆尧县| 高安市| 洪洞县| 江口县| 铜梁县| 岳阳县| 濉溪县|