递归函数Fibnacci def Fibnacci_remind(n): "带有记忆功能的递归" memo={1:1,2:1} def _internal(n,name): "内部递归方式" if n in memo: return memo[n] else: memo[n]=_internal(n-1,memo)+_internal(n-2,memo) return memo[n] return _internal(n,memo) print(Fibnacci_remind(100)) 求完美数 def favor(a): i=1; result=0; while(i<a): if(a%i==0): result+=i i+=1 if(result==a): print(a) ## else: ## print("不是完美数") ## def isPerfect(a): i=1 while(i<=a): favor(i) i+=1 favor(6) isPerfect(1000) 正则表达式 data="联系电话:029-02902999" import re rege='[0-9]{3,4}-[0-9]{7,8}' tel=re.findall(rege,data) print(tel) dd='电话:02812345678' reg='(\d{3})-\d{8}'#括号内是所要提取的东西 tel01=re.findall(reg,data) print(tel01)