![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
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 · 616 阅读 · 0 评论 -
lambda形式
lambda语句被用来创建新的函数对象,并且在运行时返回它们#!/usr/bin/python# Filename: lambda.pydef make_repeater(n): return lambda s: s*ntwice = make_repeater(2)转载 2012-11-09 09:22:08 · 683 阅读 · 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 · 735 阅读 · 0 评论 -
python 递归——冪
def pw(x,y): if y==0: return 1 else: return x*pw(x,y-1)原创 2012-10-27 22:19:55 · 713 阅读 · 0 评论 -
python 递归——阶乘
def factorial(n): if n==1:return n else: return n*factorial(n-1)原创 2012-10-27 21:59:45 · 1266 阅读 · 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 · 607 阅读 · 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 · 976 阅读 · 0 评论 -
string.maketrans此函数的调用
python version 3.2.2>>> from string import maketransTraceback (most recent call last): File "", line 1, in from string import maketransImportError: cannot import name maketrans原创 2012-10-20 12:10:33 · 5649 阅读 · 1 评论