摘要:
def cacls(x, y): try: return x/y except ZeroDivisionError: print("y can not be zerp") except TypeError: print("TypeError")print( cacls(10, 2) )print( cacls(10, 0) )print( cacls(10, "hello") )#用一个块捕捉多个异常def cacls_2(x, y): try: return x/y except (ZeroDivision... 阅读全文
posted @ 2013-11-21 20:59
sysnap
阅读(201)
评论(0)
推荐(0)
摘要:
class CPerson: name = "default" __name2 = "inaccessable name" #类作用域内的变量可以被所有实例访问 def setname(self, name): #第一个参数self,是对象本身的引用,它也是方法和函数的重要区别元素,如果方法里面没有引用任何东西,可以不用有这个参数 self.name = name def getname(self): return self.name def greeting(self): print("hello " + self.name)... 阅读全文
posted @ 2013-11-21 20:34
sysnap
阅读(168)
评论(0)
推荐(0)
摘要:
#不定长参数,这里prams是一个元组集合def print_params(*prams): for e in prams: print(e) print(prams) #输出('xxx', (1, 2, 3), 'hello')print_params("xxx", (1,2,3), "hello")#关键字参数,使用参数名提供的参数,主要用于明确每个参数的作用,例如def hello_print(greeting = "hello", name = "world"): print 阅读全文
posted @ 2013-11-21 17:57
sysnap
阅读(225)
评论(0)
推荐(0)

浙公网安备 33010602011771号