Python
Python学习
OathkeePer2x
chill out!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【Python】with指令
使用with command实现与try finally相同功能 # try: # stream = open('output.txt','wt') # stream.write('Lorem ipsum dolar') # finally: # stream.close() with open('output.txt','wt') as stream: stream.write('Lorem ipsum dolar')原创 2020-07-27 14:28:13 · 352 阅读 · 0 评论 -
【Python】属性类
如果创建properties,应当总是用这个properties。 使用properties: class Presenter(): def __init__(self,name): self.name = name #这里没有使用self.__name @property def name(self): print('In the getter') return self.__name @nam原创 2020-07-25 11:12:49 · 179 阅读 · 0 评论 -
【Python】Lambda 表达式
Lambda 表达式(lambda expression)是一个匿名函数。 函数定义:lambdaparameter_list:expression # def sorter(item): # return item['name'] presenters = [ {'name':'Susan','age':50}, {'name':'Christopher','age':30} ] # presenters.sort(key=sorter) presenters.so..原创 2020-07-25 10:38:30 · 298 阅读 · 0 评论 -
【Python】装饰器
装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象。概括的讲,装饰器的作用就是为已经存在的对象添加额外的功能。 # 实例1 userAge = input('enter your age: ') userAge = int(userAge) # 不使用语法糖 def canYou(func): def decorator(): if userAge > 1 and userAge < 10原创 2020-07-24 21:49:03 · 173 阅读 · 0 评论
分享