ITeye博客

python

共 7 篇文章

类示例

class Cat(object): __name = '' __age =0 def __init__(self,name,age): self.__name = name self.__age = age print 'init cat , name is %s;age is %d' %(name,age) def getName(self): return self.__name def getAge(self): return self.__age def setName(self,name): self.__name = name def setAge(self,age): sel…

2011-05-19 10:26 · python

枚举文件加入特定字符串

import os,os.path path = os.path class VersionOper(object): 'The version appendor class .' __dir ='' __appendStr='mrjeye' __isDebug =False __doType =() def debug(self,msg): 'prints the msg if debug mode .' if not self.__isDebug: return print 'JDebug , msg :%s' %msg def addType(self,item): 'add the …

2011-05-19 10:24 · python

列表和元组

序列:包含一些顺序排列的对象的一个结构 #和并两个列表 l1= l2= l1.extend(l2) l1,l2 (, ) l1+l2 zip() sorted()

2011-05-19 10:20 · python

访问模型

分类 Python 类型 直接访问 数字 顺序访问 字符串、列表、元组 映射访问 字典 数据类型 存储模型 更新模型 访问模型 数字 Scalar 不可更改 直接访问 字符串 Scalar 不可更改 顺序访问 列表 Container 可更改 顺序访问 元组 Container 不可更改 顺序访问 字典 Container 可更改 映射访问

2011-05-19 10:20 · python

常用模块

sys >>> import sys >>> dir(sys) types:包含所有内置TYPE >>> import types >>> dir(types) decimal:十进制浮点数 >>> import decimal >>> dir(decimal) array:高效数值数组 math/cmath:标准数学运算函数 random:多种伪随机数的实现 >>> s='' >>> for x in range(1,10) : ... s+=str(random.randrange(1,100))+' ' ... >>> s '48 19 83 40 40 3 32 70 43 ' >>…

2011-05-19 10:19 · python

常用函数及命令

is,is not = id(...)==id(...) #比较对象引用是否相同 >>> import cat >>> c1 = cat.Cat('c',4) init cat , name is c;age is 4 >>> c2=c1 >>> c3=cat.Cat('c',4) init cat , name is c;age is 4 >>> c1 is c2 True >>> c1 is c3 False >>> c2 is not c3 True >>> id(c1),id(c2),id(c3) (12799152, 12799152, 12799120) str(obj) #返回…

2011-05-19 10:18 · python

Python学习笔记

python,怎么说呢,感觉很好玩,以下说明几点笔者感兴趣的东西: 它抛弃了包裹代码块的花括号,而只依据缩进对代码块进行理解(语句有代码块的要以:结束) 注释用#,若一行以#开头,则不会被解释 FOR循环的用法不同,Python的FOR和java中的for in功能一样,具体可以参照后续代码 for语法: for iter in iter: ... else: #当且仅当在FOR循环结束时没遇到BREAK标签时执行 ... 对象的比较有些时髦: >>> 2>1<3 True #相当于:(2>1) and (1<3) >>> 2>1<0 False 这是一条正确的赋值方法:i=j=1 #i=1…

2011-05-19 10:17 · python