python偏函数及使用列表实现栈
1.偏函数
import functools
def add(a,b):
return a+b
#传统调用方式
add(1,2)
#偏函数调用方式,偏函数会先传递一个参数
func = functools.partial(add,1)
func(2)
2.栈
使用列表维护一个栈
class Stack(object):
def __init__(self):
self.data = []
def push(self,val):
self.data.append(val)
def pop(self):
self.data.pop()
def top(self):
return self.data[-1]
_stack = Stack()
_stack.push('1111')
_stack.push('2222')
_stack.pop()
_stack.pop()
```pop()
python偏函数及使用列表实现栈
http://www.jcwit.com/article/159/