Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
if else select statement:
if guess == 8: #要加冒号,不用括号,依然是==赋值
print("你他妈真是我儿子。") #不用加大括号,Python使用缩进区分代码块
print("牛逼。")
elif guess==7 or guess== 9: #多个条件分支用的是elif
print("很接近了!!")
else: #依然要加冒号
print("不对。")
print("结束了儿子。") #这个语句是程序跳出if else语句后统一打印的
Print statements (string):
print("Hello world!")
print("water"+"river") #拼接字符串
print("ha"*8) #打印指定次数字符串
The default is to print print line, the end of the wrap plus end = '', instead of the transport means is a space
Enter the statement:
input ( ""): python the built-in functions, quotes print content requires typing a character string.
loop statement:
while:
while 条件 :
statement
for:
Use in conjunction with range ().
for i in range(1,10): #结果是1 2 3 4 5 6 7 8 9
print(i,end=' ')
Affirm:
assert condition
In general we can assert in the inspection point in the program, when the need to ensure that programs a condition must be true in order for the program to work, then, assert is very useful.
If the condition is false, it throws an exception of AssertionError.
[There is no training program to assert related, and other research after I studied grammar and precautions in this section plus]