Python
文章平均质量分 76
山庄来客
这个作者很懒,什么都没留下…
展开
-
复数定义
# Complex numbers # --------------- # [Now that Python has a complex data type built-in, this is not very # useful, but it's still a nice example class] # This module represents complex numbers as instances of the class Complex. # A Complex instance z原创 2010-10-23 22:58:00 · 1159 阅读 · 0 评论 -
位向量类的分析
<br />#<br /># this is a rather strict implementation of a bit vector class<br /># it is accessed the same way as an array of python-ints, except<br /># the value must be 0 or 1<br />#<br />#所谓位向量就是由一些二进制位组成的向量。位向量可以用很少的内存来存储Boolean变量。<br /> <br />import s原创 2010-10-23 16:58:00 · 1149 阅读 · 0 评论 -
optparse模块
<!-- @page {margin:0.79in} p {margin-bottom:0.08in} --> 该模块提供了解析命令行选项的接口,其中optparse已经在2.7以后的版本中已经不再继续开发好此模块,从2.7后,将开发argparse模块。 optparse模块使用的代码示例: #!/bin/sh # # This is a lear原创 2012-04-03 15:04:07 · 4757 阅读 · 0 评论 -
python基本输入输出代码示例
#!/usr/bin/env python # -*- coding: utf-8 -*- #输入与输出 #str()与repr() for x in range(1, 11): print repr(x).rjust(2), repr(x*x).rjust(3), #逗号代表不换行 print repr(x*x*x).rjust(4) #格式化输出 for x in rang原创 2012-04-03 14:55:22 · 2221 阅读 · 0 评论 -
python面向对象代码示例
#!/usr/bin/env python # -*- coding: utf-8 -*- # a class definition class MyClass: """一个简单的类定义 A Simple Example Class""" i = 1234 #类的成员变量 def f(self):#类的成员函数 return "Hello World"原创 2012-04-03 14:57:43 · 2785 阅读 · 1 评论 -
python异常处理示例代码
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys try: f = open('myfile.txt') s = f.readline() i = int(s.strip()) except IOError as (errno, strerror): print "I/O error({0}): {原创 2012-04-03 14:56:39 · 1138 阅读 · 0 评论