摘要:python 字典的copy()方法表面看就是深copy啊,明显独立 1 d = {'a':1, 'b':2} 2 c = d.copy() 3 print('d=%s c=%s' % (d, c)) 结果: d={'a': 1, 'b': 2} c={'a': 1, 'b': 2} 修改d,看看c
        阅读全文
        | 03 2016 档案
摘要:python 字典的copy()方法表面看就是深copy啊,明显独立 1 d = {'a':1, 'b':2} 2 c = d.copy() 3 print('d=%s c=%s' % (d, c)) 结果: d={'a': 1, 'b': 2} c={'a': 1, 'b': 2} 修改d,看看c
        阅读全文
 
摘要:1 def outer(fun): # f 为用out装饰的函数 2 def inner(): 3 print('装饰器!') 4 fun() 5 print('test') 6 return inner 7 8 @outer 9 def fun1(): 10 print('fun1') 11 12
        阅读全文
 
摘要:在运行一个小脚本时,脚本从一文本文件读取数据,事实上这个文件只有一行'count:2',并取到这个2,将其转成数字。但运行,总是报错。 代码如下: 1 with open('count.txt', 'r') as file: 2 if not file.readline(): 3 pass 4 el
        阅读全文
 
摘要:pickle 有dump ,dumps ,load,loads等方法。区别在于dumps不会写入到文件。 1 import pickle 2 3 string = ['a', 2341, 'adsf'] 4 5 p_str= pickle.dumps(string) 6 print(p_str) 7
        阅读全文
 
摘要:filter(function or None, iterable) --> filter object Return an iterator yielding those items of iterable for which function(item) is true. If function
        阅读全文
 
摘要:有一列表,某一元素在列表中出现多次,要求求出该元素在列表中的索引位置。 最简单的方案就是直接对所有元素进行遍历。这里不考虑。 1 # coding:utf-8 2 name = list('12345242523552623623') 3 4 first_pos = 0 5 for i in ran
        阅读全文
 
摘要:要求,从用户处得到一个数,打印直到该数,并让用户选择是否继续。如果此数已经输出,则提示过了,并要求再次输入。
        阅读全文
 
摘要:1 import urllib.request 2 import re 3 import random 4 5 def get_source(key): 6 7 print('请稍等,爬取中....') 8 headers = [{'User-Agent':'Mozilla/5.0 (Windows
        阅读全文
 
摘要:1 #python 字典实现类似c的switch 2 3 def print_hi(): 4 print('hi') 5 6 def print_hello(): 7 print('hello') 8 9 def print_goodbye(): 10 print('goodbye') 11 12 choice = int(input('plea...
        阅读全文
 
 |