本文摘自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中的int是什么意思
Python开发tornado网站之异步与协程化的介绍
简述Python如何调用系统底层api播放wav文件
Python学什么数据库
Python3.6和3.7有什么区别
Python如何保留一位小数
Python类变量和实例变量的区别
Python实现requests发送/上传多个文件的示例
Python读写/追加excel文件demo
Python三大框架:flask框架、tornado框架、django框架简介
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python中关于复数属性以及方法运算的示例