Python basic syntax-----colons and indents
The syntax feature of Python is indentation, especially if after a conditional statement (the condition is often judged by a colon: as the closing flag),
The indentation at the same level after the colon represents the command block, at which point the indentation affects the effect of execution.
The following is a small game demo:
1. Note that the last print statement is indented to indicate that it and the previous Print statement form the command block of the else condition, and the result is not output until the else condition is met:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/88/52/wKioL1fvZGXxdhKZAABn-_7cWRQ672.png-wh_500x0-wm_3 -wmp_4-s_4247292851.png "title=" Game1.png "alt=" Wkiol1fvzgxxdhkzaabn-_7cwrq672.png-wh_50 "/>
The results of its implementation are as follows:
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/88/55/wKiom1fvZViQmwGRAAA7WiYfRdI924.png-wh_500x0-wm_3 -wmp_4-s_1107868802.png "title=" Grel1.png "alt=" Wkiom1fvzviqmwgraaa7wiyfrdi924.png-wh_50 "/>
2, when the last print statement is not indented, stating that it and the previous statement are not part of the same command block, will not be constrained by the else condition, the print statement will be out of the structure of If, in the code as a whole is a sequential structure, independent of the condition, the order of execution output:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/88/55/wKiom1fvZnDzSROJAABh5_V-3FM312.png-wh_500x0-wm_3 -wmp_4-s_1357948491.png "title=" Game2.png "alt=" Wkiom1fvzndzsrojaabh5_v-3fm312.png-wh_50 "/>
The results of its implementation are as follows:
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/88/55/wKiom1fvZuzABVfDAAB4xbGONHM793.png-wh_500x0-wm_3 -wmp_4-s_634441576.png "title=" Grel2.png "alt=" Wkiom1fvzuzabvfdaab4xbgonhm793.png-wh_50 "/>
Tip: When you finish writing code in Python's shell idle, you can press Ctrl+s to save and then press F5 to execute the program
This article is from the "Davidlee's Linux Road" blog, so be sure to keep this source http://davidlinux.blog.51cto.com/5965954/1858281
Python Basic Learning Notes (ii)