Python基本语句

1.序列解包
2.bool型
3.if /for in /while语句块
4.exec pass del语句

>>> #序列的解包
>>> x,y,z=1,2,3
>>> y
2
>>> z
3
>>> v=1,2,3
>>> v
(1, 2, 3)
>>> a,b,c=v
>>> b
2
>>> s={'one':1,'two':2}
>>> key,val=s.popitem()
>>> key
'one'
>>> val
1
>>> #语句块 :
>>> x=10
>>> while x>0:
    x=x-1
    print(x)


9
8
7
6
5
4
3
2
1
0
>>> #布尔型变量
>>> 0
0
>>> bool(0)
False
>>> bool({})
False
>>> bool([])
False
>>> bool(())
False
>>> bool(None)
False
>>> bool('')
False
>>> False==0
True
>>> True==1
True
>>> #if
>>> x=10
>>> if x>1:
    print(x)


10
#断言
>>> x=10
>>> if x>1:
    assert x==6


Traceback (most recent call last):
  File "<pyshell#8>", line 2, in <module>
    assert x==6
AssertionError
#for
>>> for word in words:
    print("word:",word)


word: one
word: two
word: three
word: four

>>> for i in range(-1,-10,-1):
    print(i)


-1
-2
-3
-4
-5
-6
-7
-8
-9
>>> 
>>> keys2={"one":1,'two':2}
>>> for i in keys2:
    print(i,keys2[i])


one 1
two 2
>>> names=['name','beth','geo','damon']
>>> ages=[1,2,3,4]
>>> zip(names,ages)
<zip object at 0x0000000003590C88>
>>> list(zip(names,ages))
[('name', 1), ('beth', 2), ('geo', 3), ('damon', 4)]
>>> pass
>>> 
>>> 
>>> 
>>> pass
>>> x=10
>>> del x
>>> x
Traceback (most recent call last):
  File "<pyshell#51>", line 1, in <module>
    x
NameError: name 'x' is not defined
>>> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值