python定义复数_Python3基础 complex 声明复数

Python : 3.7.3

OS : Ubuntu 18.04.2 LTS

IDE : pycharm-community-2019.1.3

Conda : 4.7.5

typesetting : Markdown

code

coder@ubuntu:~$ source activate py37

(py37) coder@ubuntu:~$ ipython

Python 3.7.3 (default, Mar 27 2019, 22:11:17)

Type 'copyright', 'credits' or 'license' for more information

IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: complex_num = 1 + 2j

In [2]: type(complex_num)

Out[2]: complex

In [3]: complex_num = complex(5, 6)

In [4]: type(complex_num),complex_num

Out[4]: (complex, (5+6j))

In [5]: exit

(py37) coder@ubuntu:~$ conda deactivate

coder@ubuntu:~$

source_code

class complex(object):

"""

Create a complex number from a real part and an optional imaginary part.

This is equivalent to (real + imag*1j) where imag defaults to 0.

"""

def conjugate(self): # real signature unknown; restored from __doc__

"""

complex.conjugate() -> complex

Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.

"""

return complex

def __abs__(self, *args, **kwargs): # real signature unknown

""" abs(self) """

pass

def __add__(self, *args, **kwargs): # real signature unknown

""" Return self+value. """

pass

def __bool__(self, *args, **kwargs): # real signature unknown

""" self != 0 """

pass

def __divmod__(self, *args, **kwargs): # real signature unknown

""" Return divmod(self, value). """

pass

def __eq__(self, *args, **kwargs): # real signature unknown

""" Return self==value. """

pass

def __float__(self, *args, **kwargs): # real signature unknown

""" float(self) """

pass

def __floordiv__(self, *args, **kwargs): # real signature unknown

""" Return self//value. """

pass

def __format__(self): # real signature unknown; restored from __doc__

"""

complex.__format__() -> str

Convert to a string according to format_spec.

"""

return ""

def __getattribute__(self, *args, **kwargs): # real signature unknown

""" Return getattr(self, name). """

pass

def __getnewargs__(self, *args, **kwargs): # real signature unknown

pass

def __ge__(self, *args, **kwargs): # real signature unknown

""" Return self>=value. """

pass

def __gt__(self, *args, **kwargs): # real signature unknown

""" Return self>value. """

pass

def __hash__(self, *args, **kwargs): # real signature unknown

""" Return hash(self). """

pass

def __init__(self, *args, **kwargs): # real signature unknown

pass

def __int__(self, *args, **kwargs): # real signature unknown

""" int(self) """

pass

def __le__(self, *args, **kwargs): # real signature unknown

""" Return self<=value. """

pass

def __lt__(self, *args, **kwargs): # real signature unknown

""" Return self

pass

def __mod__(self, *args, **kwargs): # real signature unknown

""" Return self%value. """

pass

def __mul__(self, *args, **kwargs): # real signature unknown

""" Return self*value. """

pass

def __neg__(self, *args, **kwargs): # real signature unknown

""" -self """

pass

@staticmethod # known case of __new__

def __new__(*args, **kwargs): # real signature unknown

""" Create and return a new object. See help(type) for accurate signature. """

pass

def __ne__(self, *args, **kwargs): # real signature unknown

""" Return self!=value. """

pass

def __pos__(self, *args, **kwargs): # real signature unknown

""" +self """

pass

def __pow__(self, *args, **kwargs): # real signature unknown

""" Return pow(self, value, mod). """

pass

def __radd__(self, *args, **kwargs): # real signature unknown

""" Return value+self. """

pass

def __rdivmod__(self, *args, **kwargs): # real signature unknown

""" Return divmod(value, self). """

pass

def __repr__(self, *args, **kwargs): # real signature unknown

""" Return repr(self). """

pass

def __rfloordiv__(self, *args, **kwargs): # real signature unknown

""" Return value//self. """

pass

def __rmod__(self, *args, **kwargs): # real signature unknown

""" Return value%self. """

pass

def __rmul__(self, *args, **kwargs): # real signature unknown

""" Return value*self. """

pass

def __rpow__(self, *args, **kwargs): # real signature unknown

""" Return pow(value, self, mod). """

pass

def __rsub__(self, *args, **kwargs): # real signature unknown

""" Return value-self. """

pass

def __rtruediv__(self, *args, **kwargs): # real signature unknown

""" Return value/self. """

pass

def __str__(self, *args, **kwargs): # real signature unknown

""" Return str(self). """

pass

def __sub__(self, *args, **kwargs): # real signature unknown

""" Return self-value. """

pass

def __truediv__(self, *args, **kwargs): # real signature unknown

""" Return self/value. """

pass

imag = property(lambda self: 0.0)

"""the imaginary part of a complex number

:type: float

"""

real = property(lambda self: 0.0)

"""the real part of a complex number

:type: float

"""

resource

[文档 - English] docs.python.org/3

[文档 - 中文] docs.python.org/zh-cn/3

[规范] www.python.org/dev/peps/pep-0008

[规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules

[源码] www.python.org/downloads/source

[ PEP ] www.python.org/dev/peps

[平台] www.cnblogs.com

[平台] gitee.com

Python具有开源、跨平台、解释型、交互式等特性,值得学习。

Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。

代码的书写要遵守规范,这样有助于沟通和理解。

每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值