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

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.

主站蜘蛛池模板: 河东区| 邯郸市| 宜宾县| 芦溪县| 亚东县| 陈巴尔虎旗| 永平县| 昭苏县| 宁国市| 红原县| 祁连县| 旬阳县| 龙南县| 龙井市| 东平县| 义乌市| 宿松县| 建湖县| 抚州市| 亳州市| 平阳县| 高尔夫| 革吉县| 丰县| 西吉县| 仁怀市| 咸丰县| 垫江县| 荥阳市| 莫力| 蓬安县| 三门县| 元阳县| 东台市| 安康市| 鄂伦春自治旗| 乌拉特后旗| 巫山县| 鞍山市| 济阳县| 云安县|