目录
会用Python, 但绝对称不上精通,因为几乎不会用python的高级特性,对python的基础也了解的不透彻,但好在有自知之明,并有深入了解的觉悟,还是孺子可教的。通篇都是讲的都是python3哦
下面的这些网址都是看过觉得对明晰概念非常有帮助的,目前也在针对python的高级特性做思维导图,而后也会放于此处。
https://www.cnblogs.com/zjltt/p/7001982.html
1. python3 全局函数
- filter() 2. map() 3. reduce() (这些全局函数可以和lambda配合使用)
(1) filter():注意返回的是迭代器
代码块中#号后面即使打印结果
def is_odd(n):
return n%2==1
newlist = filter(is_odd, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
print(newlist) # <filter object at 0x7fe13d1a47f0>
print(list(newlist)) #[1, 3, 5, 7, 9],list将迭代器转化为result
filter与lambda一起使用,代替 is_odd()函数
newlist = list(filter(lambda n: n % 2 == 1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
print(newlist) # [1, 3, 5, 7, 9]
在对象遍历处理方面,其实Python的for…in…if语法已经很强大,并且在易读上胜过了lambda。
newlist = list(x for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] if x % 2 == 1)
print(newlist) # [1, 3, 5, 7, 9]
(2) map()
(3) reduce()
2. python3 内联函数
3. 闭包与装饰器
这个还在学习中,为什么第一段代码打印的时候用的print(foo()), 而第二段代码打印的时候用的print(foo)[注意在调用foo的时候少用了一对括号],还没看明白,目前有其他事情做,等我想明白了再说
def counter():
c =[0]
print(c, "*******************")
def inc():
print(c[0], "#############")
c[0] += 1
return c[0]
return inc
foo = counter()
print(foo(), foo())
c = 100
print(foo())
print(foo())
def counter():
count = 0
def inc():
nonlocal count
count += 1
print(count, "@@@@@@@@@@@@@@@@@")
return count
print(count, "#############")
return inc()
foo = counter()
print(foo)
https://blog.csdn.net/ljt735029684/article/details/80703649
https://blog.csdn.net/xiangxianghehe/article/details/77170585
4. @staticmethod和 @classmethod
https://blog.csdn.net/alaitian/article/details/82505487
https://blog.csdn.net/ljt735029684/article/details/80714274
5. python的其他特性
python中实现了__iter__方法的对象是可迭代的
参考文献:
https://blog.csdn.net/program_developer/article/details/82024468
https://blog.csdn.net/merryxuan/article/details/89332757