【python】练习:分支循环操作

>>>if 0:
      print("Hello")

>>>if 1:
      print("Hello")
Hello
>>>if "":
      print("Hello")

>>>if []:
      print("Hello")

>>>if {}:
      print("Hello")

>>>if "Not Empty":
      print("Hello")
Hello
>>>if [10, "101"]:
      print("Hello")
Hello
>>>if True:
      print("Hello")
Hello
>>>if False:
      print("Hello")

>>>if 0 == 1:
      print("Hello")

>>>a = 10
>>>if a > 10 or a < 10:
   print("a is not 10")
else:
   print("a is 10")

a is 10
>>>if a >10:
    print("a > 10")
elif a < 10:
    print("a < 10")
else: 
    print("a = 10")

a = 10
>>>range(10)
range(0, 10)
>>>list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>for i in range(10):
       print(i, end="")
0123456789
>>>for i in [0, 1, 2, 3, 4]:
       print(i, end="")
01234
>>>for i in range(1, 10, 2):
       print(i, end="")
13579
>>>list(range(1, 10, 2))
[1, 3, 5, 7, 9]
>>>for c in "Python语言":
       print(c)
P
y
t
h
o
n
语
言
>>>for c in "Python语言":
       print(c, end=",")
P,y,t,h,o,n,,,
>>>while a > 5:
      print(a)
      a = a - 1
10
9
8
7
6

>>>while False:
       print("Hello")

>>>while True:
	print("Hello")
	break
Hello
>>>a
5
>>>while a > 0:
     a = a - 1
     if a % 2 == 0:
        continue
     print(a)

3
1
>>>try:
       a = 10/0
except:
       print("error")

error
>>>try:
       a = open("no-exist")
except:
       print("error")

error
>>>try:
    if x:
        print("Hello")
except:
       print("error")

error
>>>try:
    anyerror
except:
       print("error")

error
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值