#coding=utf-8 #python里面的字典,用{}来表示 book={'title':'python web development','year':2008} print book print 'year' in book print 'pub' in book print book.get('pub','N/A') book['pub']='Addison Wesley' print book.get('pub','N/A') for key in book: print key,…
#coding=utf-8 # 列表推倒式子 data=[x+1 for x in range(10)] print data even_numbers=[x for x in range(10) if x%2 == 0] print even_numbers # 字符串 # 字符串是不可修改的,其大小也不能改变.任何试图改变字符串长度获释修改 # 内容的行为实际上是创造了一个心的修改过的字符串而已 print 'this is a string' print "this is a string…
#coding=utf-8 #列表 book=['python','development',8] book.append(2008) print book book.insert(1,'web') print book print book[3:] print 'django' in book book.remove(8) book.pop(-1) print book print book*2 print book.extend(['with','django'])…
1.numpy.random.shuffle(x) import numpy as np x = [] for i in range(10): x.append(i) print(x) np.random.shuffle(x) print (x) 2.python 下载文件 urllib import urllib.request import os import sys import tarfile def download_and_uncompress_tarball(tarball_url…
1.冒泡排序 lis = [56,12,1,8,354,10,100,34,56,7,23,456,234,-58] def sortport(): for i in range(len(lis)-1): for j in range(len(lis)-1-i): if lis[j]>lis[j+1]: lis[j],lis[j+1] = lis[j+1],lis[j] return lisif __name__ ==…
#coding=utf-8 #内部类 class MyClass(object): class InnerClass: pass # 正则表达式 # 通过re模块来访问 import re m=re.search(r'foo','seafood') print m m.group() print m m=re.search(r'bar','seafood') print m…