摘要:
import time t = time.localtime() # 返回当前时间的九元组 time.gmtime() # 返回格林威治0时区当前时间的九元组 time.time() # 常用,与1970-1-1 8:00之间的秒数,时间戳 time.mktime(t) # 把九元组时间转成时间戳 time.sleep(1) time.asctime() # 如果有参数,是九元组形式... 阅读全文
摘要:
import time result = 0 start = time.time() # 返回运算前时间戳 for i in range(10000000): result += i end = time.time() # 返回运算后时间戳 print(result) print(end - start) 结果输出: 阅读全文
摘要:
import getpass userdb = {} def register(): username = input('username: ') if username in userdb: print('%s already exits.' % username) else: password = input('password: ... 阅读全文
摘要:
with open('./passwd') as fobj: aset = set(fobj) print(aset) with open('./mima') as fobj: bset = set(fobj) print(bset) with open('diff.txt', 'w') as fobj: fobj.writelines(aset -... 阅读全文
摘要:
# 集合相当于是无值的字典,所以也用{}表示 myset = set('hello') len(myset) for ch in myset: print(ch) aset = set('abc') bset = set('cde') aset & bset # 交集 aset.intersection(bset) # 交集 aset | bset # 并集 aset.union... 阅读全文
摘要:
adict = dict([('name', 'bob'),('age', 30)]) len(adict) hash(10) # 判断给定的数据是不是不可变的,不可变数据才能作为key adict.keys() adict.values() adict.items() # get方法常用,重要 adict.get('name') # 取出字典中name对应的value,如果没有返回None... 阅读全文