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

The if-else loop

if 1 is 3:
print "How did that happen?"
elif 1 > 3:
print ("Yikes")
else:
print ("All is well with the world")

The output of the above code is as follows:

All is well with the world

We can also do if-else and else-if blocks here too. Let's do something a little bit more complicated here. If 1 is 3, I would print How did that happen? But of course 1 is not 3, so we will fall back down to the else-if block, otherwise, if 1 is not 3, we'll test if 1 > 3. Well that's not true either, but if it did, we print Yikes, and we will finally fall into this catch-all else clause that will print All is well with the world.

In fact, 1 is not 3, nor is 1 greater than 3, and sure enough, All is well with the world. So, you know, other languages have very similar syntax, but these are the peculiarities of Python and how to do an if-else or else-if block. So again, feel free to keep this notebook around. It might be a good reference later on.

主站蜘蛛池模板: 余庆县| 扶绥县| 江西省| 边坝县| 肃宁县| 连城县| 垦利县| 达州市| 远安县| 遵义县| 大宁县| 正蓝旗| 双城市| 阳谷县| 义马市| 滁州市| 阿合奇县| 泊头市| 浮梁县| 九台市| 游戏| 秀山| 雷州市| 东阿县| 鸡东县| 紫阳县| 平乐县| 土默特左旗| 阿鲁科尔沁旗| 衢州市| 普兰县| 凉城县| 两当县| 大理市| 平遥县| 英德市| 青铜峡市| 汾西县| 武夷山市| 万盛区| 甘德县|