版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangyang20170901/article/details/84892798
时间:2018年12月8日14:56:25
--------------------------------------------------------------------------------------------
表达式包括运算符与操作数
1、运算符
2、求值顺序
控制流(3种)
1、if语句
number = 23
guess = int(input('enter an number:'))
if guess == number: #注意别忘记冒号
print('yes!')
print('(but you do not win any prizes!)')
elif guess < number:
print('no,it is a little higher than that')
else:
print('no, it is a little lower than that')
print('done') #这一句在if结束后执行
2.while语句
number = 23
running = True
while running:
guess = int(input('enter an number:'))
if guess == number: #注意别忘记冒号
print('yes!')
running = False
elif guess < number:
print('no,it is a little higher than that')
else:
print('no, it is a little lower than that')
else:
print('while is over.')
print('done') #这一句在if结束后执行
3、for循环
for i in range(1,5):
print(i)
else:
print('the for loop is over')
4、break语句
用于中断循环语句 的执行,如果中断了for或while循环,相应循环中的else块都将不会被执行。
while True:
s = input('Enter something:')
if s == 'quit':
break#跳出while循环
print('length of the string is',len(s))
print('done')
5、continue语句
跳过当前循环块中的剩余语句,并继续该循环的下一次迭代。
while True:
s = input('enter somethong:')
if s == 'quit':
break#退出while循环
if len(s)<3:
print('too small')
continue#继续下一次while
print('input is of sufficient length')
print('done')
------------------------------------------------------------------------------
结束:2018年12月8日17:06:40
进度:59/153