首页 > 脚本编程 > python学习(三)
您的足迹
  • 你没有浏览过任何文章或者你没有开启cookies。

python学习(三)

1.栈和堆,树

>>> a =[]
>>> a.append(0)
>>> a.append(1)
>>> a.append(2)
>>> a
[0, 1, 2]
>>> a.pop()
2
\
>>> a
[0, 1]
>>> a.pop()
1
>>> a.pop()
0
>>> a
[]
>>> a=[]
>>> a.append(0)
>>> a.append(1)
>>> a.append(2)
>>> a.pop(0)
0
>>> a
[1, 2]
>>> a.pop(0)
1
>>> a
[2]
>>> leaf =[0,1]
>>> leaf1 =[0,1]
>>> leaf2 =[2,3]
>>> leaf3 =[4,5]
>>> leaf4 =[6,7]
>>> br1=[leaf1,leaf2]
>>> br2=[leaf3,leaf4]
>>> root = [br1,br2]
>>> root
[[[0, 1], [2, 3]], [[4, 5], [6, 7]]]

2.字典

>>> book ={'dad':'john','mom':'lucy','bro':'james'}
>>> book
{'dad': 'john', 'bro': 'james', 'mom': 'lucy'}
>>> book['dad']
'john'
>>> dicts ={'dad':'42','mom':'35','bro':'17'}
>>> dicts
{'dad': '42', 'bro': '17', 'mom': '35'}
>>> book.clear()
>>> book
{}
>>> dicts.hav_key('dad')

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    dicts.hav_key('dad')
AttributeError: 'dict' object has no attribute 'hav_key'
>>> dicts.had_key('dad')

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    dicts.had_key('dad')
AttributeError: 'dict' object has no attribute 'had_key'
>>> dicts.has_key('dad')
True
>>> happy = dicts.copy()
>>> happy
{'dad': '42', 'bro': '17', 'mom': '35'}
>>> dicts['sister']='melisa'
>>> dicts
{'dad': '42', 'bro': '17', 'sister': 'melisa', 'mom': '35'}
>>> del dicts['sister']
>>> dicts
{'dad': '42', 'bro': '17', 'mom': '35'}
  1. 还没有评论
评论提交中, 请稍候...

留言

可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks
Feed