
正文
python怎么测函数,python中判断函数
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
python判断函数是否单调
python判断函数是否单调的方法如下:
1、先确定一个方向,然后遍历这个数组,看看是否破坏之前的方向。
2、假设不增不减是成立的,看是否有情况破坏这个条件。
相关问答
Q1: Python 编写并测试函数change(str1),其功能是对参数str1进行大小写转换?
def change(str1):
new_str = str()
for i in range(len(str1)):
if(65 = ord(str1[i]) = 90):
a = str1[i].lower()
print(a,end='')
elif(97 = ord(str1[i]) = 122):
a = str1[i].upper()
print(a,end='')
else:
a = str1[i]
print(a,end='')
return new_str
str2 = str(input("要转换的字符串:"))
print(change(str2))
Q2: python中怎么判断函数是否可以调用
Python: 测试函数是否被调用
# helper class defined elsewhere
class CallLogger(object):
def __init__(self, meth):
self.meth = meth
self.was_called = False
def __call__(self, code=None):
self.meth()
self.was_called = True
然后assert CallLogger的was_called为True就行了。但是这样的Callable不是个函数:
isinstance(object, types.FunctionType) # Callable will be False
对于这种Callable获取参数个数需要用:
inspect.getargspec(fn.__call__)






