#

# __geratteibute__
class Itcast(object):
def __init__(self,subject1):
self.subject1 = subject1
self.subject2 = 'cpp'
# 属性访问时拦截器,打log日志
def __getattribute__(self,obj):
print("=====1>%s"%obj)
if obj == 'subject1':
print('log subjiect')
return 'redirect python'
else:
temp = object.__getattribute__(self,obj)
print("====2>%s"%str(temp))
return temp

def show(self):
print("this is Itcast")

s = Itcast("python")
print(s.subject1)
print(s.subject2)
# =====1>subject1
# log subjiect
# redirect python
# =====1>subject2
# ====2>cpp
# cpp

s.show()
# =====1>show
# ====2><bound method Itcast.show of <__main__.Itcast object at 0x000001BC04FE5AC8>>
# this is Itcast

# 1.先获取show属性对应的结果,,,,,应该是一个方法
# 2.方法()

class Person(object):
def __getattribute__(self,obj):
print("----test----")
if obj.startswith("a"): #startswith以什me开头
return 'r'
else:
# return self.test
return object.__getattribute__(self,obj)

def test():
print("hehehe")

# 访问属性之前肯定会访问__getattribute__

t = Person()
# t.a #hahah
# t.b #会让程序死掉

# 内建函数
# range
# python2中返回直接是一个列表
# python3中不会 直接返回一个列表

# xrange 节省内存空间

# map函数
# map函数会根据提供的函数对指定序列做映射

# map(...)
# map(function,sequence[,sequence,...]) ->list

# function:是一个函数
# sequence:是一个或多个序列,取决于function需要几个参数
# 返回值是一个list

# 参数序列中的每一个元素分别调用function函数,返回包含每次function函数返回值得list

# 函数需要一个参数
# map(lambda x: x*x,[1,2,3])
# map(lambda x,y:x+y,[1,2,3],[4,5,6])

def f1(x,y):
return (x,y)

l1 = [0,1,2,3,4,5,6]
l2 = [0,1,2,3,4,5,6]

l3 = map(f1,l1,l2)
print(l3)
# <map object at 0x000001EDB5C75DA0>

# filter函数
a = filter(lambda x:x%2, [1,2,3,4])
print(a)
# <filter object at 0x000001BA5AFF5E10>
for tmp in a:
print(tmp)

# 1
# 3

filter(None,"she")

# reduce函数
# reduce函数,reduce函数会对参数序列中元素进行累积

# b = reduce(lambda x,y: x+y, [1,2,3,4])
# print(b)

# reduce(lambda x,y: x+y,["aa","bb","cc"],"dd")
# "ddaabbcc"

c = [1,3,2,9,76,54243]
c.sort()
print(c)

c = [1,3,2,9,76,54243]
# sorted函数
sorted([1,4,3,2])
print(sorted([1,4,3,2]))

最新文章

  1. c++中的peek函数
  2. LA 6856 Circle of digits 解题报告
  3. Web前端开发工程师为什么讨厌IE6!
  4. Android中Activity之间访问互传参数
  5. 关于oracle数据库备份还原-impdp,expdp
  6. 再起航,我的学习笔记之JavaScript设计模式03
  7. less基础语法
  8. 调用链监控 CAT 之 入门
  9. framework7 入门(数据绑定)
  10. pip 安装问题
  11. C语言之指针若干问题
  12. ES6 generators in depth 一(译)
  13. 章节二、1-java概述-数据类型
  14. hibernate框架学习之数据查询(QBC)
  15. Spring整合MyBatis(简单登录Demo)
  16. 05python下
  17. wait()和notify()的理解与使用
  18. Linux命令区
  19. oracle 数据库io 异常,错误代码17002 解决办法
  20. WIN2008服务器不能复制粘贴怎么办

热门文章

  1. This is a DynamicProxy2 error:
  2. [转] 理解NLP中的卷积&amp;&amp;Pooling
  3. SQL Server - GO
  4. C++ 11 snippets , 1
  5. MySQL全备+binlog恢复方法之伪装master【原创】
  6. select2使用方法总结
  7. MySQL数据库的一些方法使用
  8. 切换目录查询目录 tcp
  9. JMeter 中_time 函数的使用(时间戳、当前时间)
  10. 大数据python词频统计之hdfs分发-cacheArchive