发布时间:2012-12-27 10:43:07
二十七、局部变量的使用 age = 22 name = 'Swaroop' print '%s is %d years old' % (name, age) #注意使用 print 'Why is %s playing with that python?' % name 二十八、python中语句很长的时候 s = 'this is a string .\ This continues the string ' print s......【阅读全文】
发布时间:2012-12-27 10:41:09
二十一、使用函数* lambda语句被用来创建新的函数对象,并且在运行时返回它们 def make_repeater(n): return lambda s: s*n #这个最他妈重要 twice = make_repeater(2) print twice('word') print twice(5) --------------------------- 结果 wordword 10 &nbs......【阅读全文】
发布时间:2012-12-27 10:39:16
十七、python中向本地写入文件 将新的内容写入到D:\soft\poem.txt中去 poem = '''\ Programming is fun When the work is done if you wanna make your work also fun: use Python! ''' f = file('D:\soft\poem.txt', 'w') # 这里使用的是写模式,还有读模式‘r’,追加模式('a') f.write(poem)......【阅读全文】
发布时间:2012-12-27 10:37:30
十三、__del__的使用 有一个特殊的方法__del__,它在对象消逝的时候被调用。对象消 逝即对象不再被使用,它所占用的内存将返回给系统作它用 十四、class的使用 class person: count = 0 def __init__(self,name,age): self.name=name self......【阅读全文】
发布时间:2012-12-27 10:35:52
十一、元组的使用 元组和列表十分类似,只不过元组和字符串一样是不可变的 即你不能修改元组。元组通过圆 括号中用逗号分割的项目定义。元组通常用在使语句或用户定义的函数能够安全地采用一组值 的时候,即被使用的元组的值不会改变 zoo = ('wolf', 'elephant', 'penguin') #使用圆括号来添加成员的 print 'Number of animals in the zoo is', len(zoo) new_zoo = ('monkey', 'dolphin', zoo)......【阅读全文】