标签:
# -*- coding: cp936 -*-
#斐波那契数列
def fibs(num):
rest=[0,1]
for i in range(num-2):
rest.append(rest[-2]+rest[-1])
return rest
print fibs(10)
#递归
def f(n):
if n==1:
return 1
else:
return n*f(n-1)
print f(6)
#密
def p(x,n):
if n==0:
return 1
else:
return x*p(x,n-1)
print p(2,1)
"""
isalnum()
2011-09-26 10:20:41| 分类: 随记 | 标签:isalnum isalpha isdigit |字号 订阅
该函数的说明是这样的:
Checks for an ASCII alphanumeric character; it is equivalent to "isalpha(c) or isdigit(c)".
意思是说检查一个Ascii 字母数字字符,等同于isalpha,或者isdigit
比如:
>>> seq=["foo","x41","?~","****"]
>>> [x for x in seq if x.isalnum()]
[‘foo‘, ‘x41‘]
s.isalnum() 所有字符都是数字或者字母
>>>
"""
"""
girls=[‘alice‘,‘bernice‘,‘clarice‘]
boys=[‘chris‘,‘arnold‘,‘bob‘]
letterGirls={}
for girl in girls:
letterGirls.setdefault(girl[0],[]).append(girl)
print [(b+‘+‘+g) for b in boys for g in letterGirls[b[0]]]
"""
f=[0,1]
num=input(‘num:‘)
for i in range(num-2):
f.append(f[-2]+f[-1])
print f
f=[0,1]
nun=input(‘n:‘)
for i in range(nun-2):
print i,
print f[nun]
标签:
原文地址:http://www.cnblogs.com/mhxy13867806343/p/4156460.html