
python
文章平均质量分 56
爪哇天河
路漫漫其修远兮
展开
-
Python中类的用法
# -*- coding: cp936 -*- #类的定义 def scope_test(): def do_local(): spam = "local spam" def do_nonlocal(): #3.0之后的用法 nolocal spam spam = "nonlocal spam" def do_global()原创 2014-11-10 11:58:34 · 694 阅读 · 0 评论 -
python的安装(版本2.7.8)
windows使用python编程时,需要一次接触python需要从网站上下载原创 2014-10-13 16:24:49 · 866 阅读 · 0 评论 -
Python列表操作自定义函数(二)
# -*- coding: cp936 -*- #list函数形参传递 s = "www.baidu.com" print s li1 = list(s) print 'li1',li1 #定义一个函数来剔除字符串中的. def count_char(listchars): while "." in listchars: r = listchars.pop(listcha原创 2014-10-30 11:14:45 · 1563 阅读 · 0 评论 -
python的条件分支语句(if)
count = int(raw_input("please input your math record:")) print count if count > 90: print 'a' elif count > 80: print 'b' elif count > 70: print 'c' elif count > 60: print 'd' else:原创 2014-10-16 11:33:29 · 2729 阅读 · 0 评论 -
Python列表操作(三)
# -*- coding: utf-8 -*- #函数进阶 lambda匿名函数 X:X+n :前为参数 后卫函数体 from math import pi def make_incrementor(n): return lambda x: x + n #f是函数make_incrementor(42)的返回值 即f = lambda x: x + n f = make_increme原创 2014-11-04 09:55:55 · 526 阅读 · 0 评论 -
Python不定参数自定义函数
# -*- coding: gbk -*- #python进阶探究 a,b = 0,1 while b < 100: print str(b)+',', a,b = b,a+b print("-"*40) if b == 10: pass #这句话什么都不做 #定义一个方法 def fib(n): a,b = 0,1 while b < n:原创 2014-11-04 10:00:45 · 889 阅读 · 0 评论 -
Python列表序列及字典的操作
# -*- coding: utf-8 -*- #嵌套列表推导式 matrix = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], ] print [[row[i] for row in matrix] for i in range(4)] #等价于 transposed = [] for i in range(4):原创 2014-11-04 10:46:28 · 437 阅读 · 0 评论 -
Python循环语句(while)
# -*- coding: cp936 -*- i = 0 while False: print i,'Hello world!' i = i + 1 if i > 100: break #直接跳出循环体 else是循环体一部分 所以else部分也不执行 else: #可以加else再循环结束时调用原创 2014-10-20 11:25:52 · 689 阅读 · 0 评论 -
Python模块的定义
将写好的python转载 2014-11-04 14:38:08 · 574 阅读 · 0 评论 -
python循环控制语句(for)
# -*- coding: cp936 -*- #循环字符串 s1 = "Hello world!" i = 0 for c in s1: print format(i,"2d"),c i = i + 1 else: print "out for!" #循环列表 列表数据可修改 i = 0 list1 = [1,3,5,"nihao",10,18,14.5] for va原创 2014-10-21 09:52:03 · 760 阅读 · 0 评论 -
Python字符串的处理(一)
# -*- coding: cp936 -*- #可以直接使用字符串下标 index s1 = "Hello world!" print s1[1] #转义字符 s2 = "aa\nbb" print s2 #前面加r 表示原始字符串 不转义 s3 = r"aa\nbb" print s3 #打印结果:aa\nbb #前面加u 表示unicode 转义 s3 = u"aa\nbb" prin原创 2014-10-21 16:03:23 · 484 阅读 · 0 评论 -
Python列表操作(一)
# -*- coding: cp936 -*- #文件读操作 全部读出一次性 file_obj = open('D:\pythonRead.txt','r') s = file_obj.read() # print s file_obj.close() #文件读操作 指定读取长度 file_obj = open('D:\pythonRead.txt','r') s = file_obj.rea原创 2014-10-30 10:36:31 · 440 阅读 · 0 评论 -
python的变量
python的变量与c语言java不同,不需要提前定义变量的格式。python会根据赋值自动判断变量的原创 2014-10-13 16:36:50 · 413 阅读 · 0 评论 -
python自定义函数(二)
# -*- coding: cp936 -*- #给函数的参数设定预定值 def test_function(val1,val2 = 20): #形参 有预定值的参数写到最右面,否则编译报错 print val1, #加,打印到一行 print val2 c = val1 + val2 return c print 'entry programe!' s =原创 2014-10-14 10:58:37 · 357 阅读 · 0 评论 -
python web框架(转载自龙飞非龙)
原文链接地址:浅谈Python web框架转载 2014-11-11 10:42:12 · 932 阅读 · 0 评论 -
使用Django搭建一个简单的Python Web工程
配置好python及django之后就可以使用框架搭建一个简单的web project原创 2014-11-12 16:19:55 · 4502 阅读 · 0 评论 -
Python+Django连接mysql 自动创建model
python+django对数据库的支持是非常多的。可以使用默认的sqlite数据库。原创 2014-11-13 11:25:20 · 6761 阅读 · 0 评论 -
Python3.x和Python2.x的区别
1.性能 Py3.0运行 pystone benchmark的速度比Py2.5慢30%。Guido认为Py3.0有极大的优化空间,在字符串和整形操作上可 以取得很好的优化结果。 Py3.1性能比Py2.5慢15%,还有很大的提升空间。 2.编码 Py3.X源码文件默认使用utf-8编码,这就使得以下代码是合法的: >>> 中国 = 'china' >>>转载 2014-11-12 15:45:46 · 352 阅读 · 0 评论 -
Django的安装与配置(Windows)
Python的下载地址(可以根据读者当前版本自行下载):http://www.python.org/download/releases/3.3.4/ Django的下载地址:https://www.djangoproject.com/download/ 目前Django 1.6x以上版本已经完全兼容Python3x原创 2014-11-12 14:56:44 · 510 阅读 · 0 评论 -
Python文件读写方式
# -*- coding: cp936 -*- #文件读操作 全部读出一次性 file_obj = open('D:\pythonRead.txt','r') s = file_obj.read() # print s file_obj.close() #文件读操作 指定读取长度 file_obj = open('D:\pythonRead.txt','r') s = file_obj.rea原创 2014-10-29 16:38:36 · 1132 阅读 · 0 评论 -
python的输入输出方式
使用代码显示:原创 2014-10-13 16:35:36 · 733 阅读 · 0 评论 -
python简单网络爬虫程序
需要提前导入httplib2 import urllib import webbrowser as web url = "http://www.baidu.com" content = urllib.urlopen(url).read() open("demo.html","w").write(content) web.open_new_tab('demo.html')原创 2014-10-13 16:43:28 · 549 阅读 · 0 评论 -
python变量实例
由输出结果可以看出python变量其实相当于c语言指针。 x = 12 y = 13 print 'x = ',x,id(x) print 'y = ',y,id(y) x = y print 'x = ',x,id(x) print 'y = ',y,id(y) x = 15 y = 16 print 'x = ',x,id(x) print 'y = ',原创 2014-10-13 16:38:38 · 384 阅读 · 0 评论 -
python自定义函数(一)
# -*- coding: cp936 -*- ''' python自定义函数 函数无返回值类型 def function_name(parameters): 冒号 (TAB)statement1 没有TAB缩进格式会不正确 无法编译 不用花括号 statement2 return reVal 返回值 ''' def te原创 2014-10-14 10:28:24 · 786 阅读 · 0 评论 -
Python输入输出
# -*- coding: utf-8 -*- import math #输入输出 s = 'Hello, world.' print str(s) #结果:Hello, world. print repr(s) #结果:'Hello, world.' print repr((10, 20, ('spam', 'eggs'))) #结果:(10, 20, ('spam', 'eggs')) ''原创 2014-11-06 14:50:05 · 476 阅读 · 0 评论