易截截图软件、单文件、免安装、纯绿色、仅160KB

python学习1 使用类

#使用类
class CPerson:
#类变量好比C++中的静态成员变量
population = 0

def SayHi(self):
print('Hello World')
def HowMany(self):
if CPerson.population == 1:
print('I am the only person here.')
else:
print(('We have %d persons here.') % CPerson.population)

#类中有很方法的名字有特殊的意义
#__init__好比C++中的构造函数
def __init__(self, name):
self.name = name
print(('Initializing %s') % self.name)
CPerson.population += 1

#__del__好比C++中的析构函数
def __del__(self):
CPerson.population -= 1
if CPerson.population == 0:
print('I am the last one.')
else:
print(('There are still %d people left.') % CPerson.population)

p = CPerson('123456')
p.SayHi()
p.HowMany()
p0 = CPerson('987654321')
p0.SayHi()
p0.HowMany()
p.SayHi()
p.HowMany()
print('------------------------------------------')
#使用继承,多态现象
class SchoolMember:
def __init__(self, name ,age):
self.name = name
self.age = age
print(('Initialized SchoolMember:%s') % self.name)
def Tell(self):
print(('Name:%s, Age:%d') % (self.name, self.age))
class Teacher(SchoolMember):
def __init__(self, name, age, salary):
SchoolMember.__init__(self, name, age)
self.salary = salary
print(('Initialized Teacher:%s') % self.name)
def Tell(self):
SchoolMember.Tell(self)
print(('Salary:%d') % self.salary)
class Student(SchoolMember):
def __init__(self, name, age, marks):
SchoolMember.__init__(self, name, age)
self.marks = marks
print(('Initalized Student:%s') % self.name)
def Tell(self):
SchoolMember.Tell(self)
print(('Marks:%d') % self.marks)
t = Teacher('liyong', 30, 30000)
s = Student('swap', 22, 75)
members = [t, s]
for member in members:
print('######


相关文档:

Python 使用C代码——swig

Ref : http://www.swig.org/translations/chinese/tutorial.html
假设你有一些c你想再加Python.。举例来说有这么一个文件example.c
 /* File : example.c */
 #include <time.h>
 double My_variable = 3.0;
 int fact(int n) {
     if (n <= 1) return 1;
&nbs ......

自动化测试中Python与C/C++的混合使用


背景
项目的
自动化测试中已经使用了基于Python
脚本的框架,自动化过程中最关键的问题就是如何实现桩模块。运用
Python
强大的功能,实现任何桩模块都是可能的,但是是否必须完全使用
Python
实现模块逻辑,成本是一个决定性因素。在桩模块逻辑简单的情况下,使用
Python
模拟模块逻辑不但使自动化测试的结构清 ......

python类型转换、数值操作


2008-12-21
python类型转换、数值操作
关键字: python类型转换、数值操作
python类型转换
Java代码
函数                      描述   
int(x [,base ])    ......

python算法实践4 快速排序

#快速排序
def Partition(mylist, low, high):
tmp = mylist[low]
while low < high:
while low < high and mylist[high] >= tmp:
high = high - 1
if low < high:
mylist[low] = mylist[high]
low = low + 1
while low < hi ......

python算法实践7 归并排序

def MergeSort(mylist, low, mid, high):
i = low
j = mid + 1
tmp = []

while i <= mid and j <= high:
if mylist[i] <= mylist[j]:
tmp.append(mylist[i])
i = i + 1
else:
tmp.append(mylist[j])
j = j + 1 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号