-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathbase.py
More file actions
45 lines (33 loc) · 733 Bytes
/
base.py
File metadata and controls
45 lines (33 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
"""
This document is created by magic at 2018/8/16
"""
class BaseStack:
"""
doc 利用python实现一个栈
"""
def __init__(self):
self.items = []
def push(self, value):
self.items.append(value)
def pop(self):
item = self.items[-1]
self.items = self.items[0:self.size - 1]
return item
@property
def size(self):
return len(self.items)
@property
def empty(self):
return len(self.items) == 0
if __name__ == '__main__':
s = BaseStack()
s.push('123')
s.push("magic")
s.push(5)
print(s.items)
print(s.pop())
print(s.pop())
print(s.size)
print(s.pop())
print(s.empty)