一.多任务(多线程) 多线程特点:(1)线程的并发是利用cpu上下文的切换(是并发,不是并行)(2)多线程执行的顺序是无序的(3)多线程共享全局变量(4)线程是继承在进程里的,没有进程就没有线程(5)GIL全局解释器锁(6)只要在进行耗时的IO操作的时候,能释放GIL,所以只要在IO密集型的代码里,用多线程就很合适 # 无序的,并发的 import threading import time def test1(n): time.sleep(1) print('task', n) for i i
一.Python3.6新特性 1.新的格局化字符串办法 <p "="">新的格局化字符串办法,即在一般字符串前增加 f 或 F 前缀,其效果相似于str.format().比方 name = "red" print(f"He said his name is {name}.") # 'He said his name is red.' <p "="">相当于: print("
getsizeof的局限 python非内置数据类型的对象无法用sys.getsizeof()获得真实的大小,例: import networkx as nx import sys G = nx.Graph() l = [i for i in xrange(10000)] print "size of l:", sys.getsizeof(l) G.add_nodes_from(l) print "size of graph:", sys.getsizeof(G)