zoukankan      html  css  js  c++  java
  • crawler 听课笔记 碎碎念 3 关于python的细枝末节的回顾复习

    和廖雪峰大神的教程学了几遍后,还是出现了许多不足,于是就做一些回顾,列出一些python的细节问题,有一些就提一下,如果发现不清楚的话

    还请移步https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000继续埋头学习吧,加油啦程序员!

    判断与循环,后面一定要加“:”      

    if elif else                 

    is

    in

    assert

    for while contiue break

    异常

    raise try except finally

    with as

    作用域

    global nonlocal

    匿名函数与协程

    yield lambda

    注意break和continue的区别  没有++--   for循环值作用于容器

    函数也是对象  编程简介map  reduce   lambda x:x*100直接说明x的取法

    list[]就是数组     允许负数索引,append用于插入函数,但是无法合并两个是列表的元素,这个时候要用extend

            pop()删除默认最后一个元素,pop(m)删除指定

            排序.sort()    可以用.sort(key= lambda x : x[0])更加细致的排每一个元素里面的元素

    tuple()  相当于初始化以后不能更改的数组

    set       相当于没有重复元素的数组

    字典di= {}  可以理解为key和value对应的hash表

           遍历for k in di:或者是for k,v in di.items:

    数组切片  [0:3]前三个  [-1,-4,-1]就是最后三个  [::-1]切片反转数组      切片是复制,所以改变不会影响原来的list

    修改字符串  合拼 s='v'.join(li)其中li是一个list  

    切割字符串 s.split(',')把一个字符串按照','为隔切开来变成单个的

    面对对象 一切皆是对象

    常用type查看对象类型  

    dir查看属性和方法  self很重要,相当于c++的指针

    文件的读写

    f= open('text,txt','r')  r就是read   w就是write   rw w+...    f.read()全读                 一行行读的话就for line in f.readlines  一般用tryfinally最后加上f.close()

              这里的话一般用with...as...的方法

    with open('text.txt') as f:
        for line in f.readlines():
            print (line)

    这样就不用担心忘记关闭文件了

    多线程

    import threading
    
    def thread_func(x):
        print('%d'%(x*100))
    
    threads = []
    for i in range(5):
        threads.append(threading.Thread(target=thread_func,args=(100,)))
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()

    args=(100,)中那个逗号千万不能忘记

    错误处理

    try:
        r= 10/0
    except ZeroDivisionError as e:
        print(type(e))
        print(e)
    finally:
      #这一步主要是防止资源泄露
    print('Always come here.')

    那么看到这里要是你发现基本没什么问题,说明你在基础上其实底子已经不错了,更多的就是自己去写去看了

  • 相关阅读:
    METHODS OF AND APPARATUS FOR USING TEXTURES IN GRAPHICS PROCESSING SYSTEMS
    Display controller
    Graphics processing architecture employing a unified shader
    Graphics-Processing Architecture Based on Approximate Rendering
    Architectures for concurrent graphics processing operations
    Procedural graphics architectures and techniques
    DYNAMIC CONTEXT SWITCHING BETWEEN ARCHITECTURALLY DISTINCT GRAPHICS PROCESSORS
    Thermal zone monitoring in an electronic device
    System and method for dynamically adjusting to CPU performance changes
    Framework for Graphics Animation and Compositing Operations
  • 原文地址:https://www.cnblogs.com/xingnie/p/9689906.html
Copyright © 2011-2022 走看看