
python
fengling132
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python3.2 字典
people = { 'Alice':{ 'phone':'2341', 'addr':'Foo drive 23' }, 'Beth':{ 'phone':'9102', 'addr':'Bar street 42'原创 2012-10-20 13:22:03 · 667 阅读 · 0 评论 -
lambda形式
lambda语句被用来创建新的函数对象,并且在运行时返回它们 #!/usr/bin/python # Filename: lambda.py def make_repeater(n): return lambda s: s*n twice = make_repeater(2)转载 2012-11-09 09:22:08 · 737 阅读 · 0 评论 -
在函数中接收元组和列表
def powersum(power, *args): '''Return the sum of each argument raised to specified power.''' total = 0 for i in args: total += pow(i, power) return total原创 2012-11-09 09:20:26 · 776 阅读 · 0 评论 -
python 递归——冪
def pw(x,y): if y==0: return 1 else: return x*pw(x,y-1)原创 2012-10-27 22:19:55 · 756 阅读 · 0 评论 -
python 递归——阶乘
def factorial(n): if n==1:return n else: return n*factorial(n-1)原创 2012-10-27 21:59:45 · 1315 阅读 · 0 评论 -
python------continue语句
while True: s=input('Input a word:') if s=='quit': break if len(s)<3: print ('your word is not enough') continue原创 2012-10-31 14:43:07 · 647 阅读 · 0 评论 -
try/exception加个else子句,只要有错误发生,程序会不断要求重新输入
while True: try: x=int(input('Please input a number for x:')) y=int(input('Please input a number for y:')) print(x/y) except: print ('fuck you,try again') else:break原创 2012-10-29 21:57:23 · 1009 阅读 · 0 评论 -
string.maketrans此函数的调用
python version 3.2.2 >>> from string import maketrans Traceback (most recent call last): File "", line 1, in from string import maketrans ImportError: cannot import name maketrans原创 2012-10-20 12:10:33 · 5759 阅读 · 1 评论