第一个python程序:print("hello,world")
输入:input()
注释:单行注释‘#’,多行注释’ ''' ''' ’
关键字:['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
查看关键字代码:import keyword
keyword.kwlist
if判断语句:if 要判断的条件:
条件成立是要做的事
elif 判断条件:
条件满足做的事
else:条件不成立时做的事 #else必须和if一起使用
例子:
score=int(input("输入成绩:")) if score>90 and score<100: print("9") elif score>80 and score<90: print("8") elif score>70 and score<80: print("7") elif score>60 and score<70: print("6") else: print("5.9")
循环:while 条件:
语句
for 临时变量 in 列表或者字符串等可迭代变量
循环满足条件时执行的代码
break:立刻结束当前循环
continue:用来结束本次循环,紧接着执行下一次的循环