问题一:
#调用foo函数传入1
#调用class_foo传入1
#调用static_foo传入1
class A(object): def foo(self,x): print('executing foo(%s%s)'%(self,x)) @classmethod def class_foo(cls,x): print('executing foo(%s%s)' % (cls, x)) @staticmethod def static_foo(x): print('executing foo(%s)' % x) a = A() a.foo(1) a.class_foo(1) a.static_foo(1)问题二:
一个函数用于替换某个字符串的一个或几个字串
def replcestr(replaced_str,new_str): after_str = pstr.replace(replaced_str,new_str) print(after_str) pstr = input('请输入源字符串') replaced_str = input("请输入被替换的字符串") new_str = input('请输入新选的字符串') replcestr(replaced_str,new_str)请输入源字符串world ha ha
请输入被替换的字符串ha ha
请输入新选的字符串wwwww
world wwwww
问题三:
用python使list [1,2,3,...100]变为 [[1,2,3],[4,5,6]....]
a = [[x,y,z] for x in range(1,98,) for y in range(2,99)for z in range(3,100)if y-x ==1 if z-y==1 ] b = [x for x in range(1,101)] c = [[m,n,l] for m in b for n in b for l in b if n-m ==1 if l-n==1] print(c)