本文摘自php中文网,作者黄舟,侵删。
这篇文章主要介绍了Python复数属性和方法运算操作,结合实例形式分析了Python复数运算相关操作技巧,代码注释备有详尽说明,需要的朋友可以参考下本文实例讲述了Python复数属性和方法运算操作。分享给大家供大家参考,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | class Complex ( object ):
version = 1.0
def __init__( self ,rel = 15 ,img = 15j ):
self .realPart = rel
self .imagPart = img
def creatComplex( self ):
return self .realPart + self .imagPart
def getImg( self ):
img = str ( self .imagPart)
img = img[: - 1 ]
return float (img)
def test():
print "run test..........."
com = Complex ()
Cplex = com.creatComplex()
if Cplex.imag = = com.getImg():
print com.getImg()
else :
pass
if Cplex.real = = com.realPart:
print com.realPart
else :
pass
print "the religion complex is :" ,Cplex
print "the conjugate complex is :" ,Cplex.conjugate()
if __name__ = = "__main__" :
test()
|
运算结果:
以上就是Python中关于复数属性以及方法运算的示例的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python如何计算平均值
Python怎么改字体
中谷教育Python视频教程资源推荐
Python numpy函数中linspace实现创建等差数列的实例分享
什么是Python线程模块?九种方法助你了解线程模块
Python update函数定义及作用实例解析
Python采集代理ip并判断是否可用和定时更新的方法
Python之spider
分享Python如何实现头像拼接技术/
总结用Python 操作 pdf 的几种方法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python中关于复数属性以及方法运算的示例