python之几个典型的语句

1 while

condition=1;
while(condition<10):
    print(condition)
    condition=condition+1;
condition=1;
while condition<10:
    print(condition)
    condition=condition+1;

2 for

examle_list=[12,234,454,343,2,2,334,123,545,256,33,24,26,26]
for i in examle_list:
    print(i)
    print("in for")  这个语句还是在for循环里面
print('out of for')  这个语句由于没有四个空格 所以是在for循环外面

输出1-9
for i in range(1,10):
    print(i) 

输出1 3 5 7 9

range(,,stepsize)

for i in range(1,10,2):
    print(i)

3 if

x,y,z=1,2,3
if x<y<z:
    print('x is less than y and y is less than z') 正确
x,y,z=1,2,0
if x<y>z:
    print('x is less than y and y is more than z') 正确
x,y,z=1,2,0
if x<=y:
    print('x is less than y or eaual to y') 正确
x,y,z=2,2,0
if x==y:
    print('x is eaual to y') 正确 不能写x=y =是赋值运算 ==才表示判断是否相等
x,y,z=1,2,0
if x!=y:
    print('x is not eaual to y') 正确

4 if else

x,y,z=1,2,0
if x<y:
    print('x is less than y')
else:
    print('x is greater than y')

5 if elif else

elif=else if

x,y,z=1,2,0
if x<1:
    print('x is less than 1')
elif x>1:
    print('x is greater than y')
else:
    print('x is equal to 1')

只能打印出x<-1这个结果:

x,y,z=-3,2,0
if x>1:
    print('x is more than 1')
elif x<-1:
    print('x is less than -1')
elif x<-2:
    print('x is less than -2')
else:
    print('nothing')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值