python的基础知识


会用Python, 但绝对称不上精通,因为几乎不会用python的高级特性,对python的基础也了解的不透彻,但好在有自知之明,并有深入了解的觉悟,还是孺子可教的。通篇都是讲的都是python3哦
下面的这些网址都是看过觉得对明晰概念非常有帮助的,目前也在针对python的高级特性做思维导图,而后也会放于此处。
https://www.cnblogs.com/zjltt/p/7001982.html

1. python3 全局函数

  1. 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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值