Python built-in function 3-complex ()

Source: Internet
Author: User
Tags pow

Help on the class complex in module __builtin__:


Class Complex (object)

| Complex (real[, imag]), complex number

|

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

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

|

| Methods defined here:

|

| __abs__ (...)

| x.__abs__ () <==> ABS (x)

|

| __add__ (...)

| x.__add__ (y) <==> x+y

|

| __coerce__ (...)

| x.__coerce__ (y) <==> coerce (x, y)

|

| __div__ (...)

| x.__div__ (y) <==> x/y

|

| __divmod__ (...)

| x.__divmod__ (y) <==> divmod (x, y)

|

| __eq__ (...)

| x.__eq__ (y) <==> x==y

|

| __float__ (...)

| x.__float__ () <==> float (x)

|

| __floordiv__ (...)

| x.__floordiv__ (y) <==> x//y

|

| __ge__ (...)

| x.__ge__ (y) <==> x>=y

|

| __getattribute__ (...)

| x.__getattribute__ (' name ') <==> x.name

|

| __getnewargs__ (...)

|

| __gt__ (...)

| x.__gt__ (y) <==> x>y

|

| __hash__ (...)

| x.__hash__ () <==> hash (x)

|

| __int__ (...)

| x.__int__ () <==> int (x)

|

| __le__ (...)

| x.__le__ (y) <==> x<=y

|

| __long__ (...)

| x.__long__ () <==> long (x)

|

| __lt__ (...)

| x.__lt__ (y) <==> x<y

|

| __mod__ (...)

| x.__mod__ (y) <==> x%y

|

| __mul__ (...)

| x.__mul__ (y) <==> x*y

|

| __ne__ (...)

| x.__ne__ (y) <==> x!=y

|

| __neg__ (...)

| x.__neg__ () <==>-X

|

| __nonzero__ (...)

| x.__nonzero__ () <==> x! = 0

|

| __pos__ (...)

| X.__pos__ () <==> +x

|

| __pow__ (...)

| x.__pow__ (y[, z]) <==> pow (x, y[, z])

|

| __radd__ (...)

| x.__radd__ (y) <==> y+x

|

| __rdiv__ (...)

| x.__rdiv__ (y) <==> y/x

|

| __rdivmod__ (...)

| x.__rdivmod__ (y) <==> divmod (y, x)

|

| __repr__ (...)

| x.__repr__ () <==> repr (x)

|

| __rfloordiv__ (...)

| x.__rfloordiv__ (y) <==> y//x

|

| __rmod__ (...)

| x.__rmod__ (y) <==> y%x

|

| __rmul__ (...)

| x.__rmul__ (y) <==> y*x

|

| __rpow__ (...)

| y.__rpow__ (x[, z]) <==> pow (x, y[, z])

|

| __rsub__ (...)

| x.__rsub__ (y) <==> y-x

|

| __rtruediv__ (...)

| x.__rtruediv__ (y) <==> y/x

|

| __str__ (...)

| X.__STR__ () <==> str (x)

|

| __sub__ (...)

| x.__sub__ (y) <==> x-y

|

| __truediv__ (...)

| x.__truediv__ (y) <==> x/y

|

| Conjugate (...)

| Complex.conjugate (), complex

|

| Returns the complex conjugate of its argument. (3-4j). Conjugate () = = 3+4j.

|

| ----------------------------------------------------------------------

| Data descriptors defined here:

|

| Imag

| The imaginary part of a complex number

|

| Real

| The real part of a complex number

|

| ----------------------------------------------------------------------

| Data and other attributes defined here:

|

| __new__ = <built-in method __new__ of type object>

| T.__NEW__ (S, ...)-A new object with type S, a subtype of T

Class Complex ([Real[, Imag]])

Return a complex number with the value real + imag*1j or convert a string or number to a complex number. If The first parameter is a string, it'll be interpreted as a complex number and the function must be called without a s Econd parameter. The second parameter can never be a string. Each argument is any numeric type (including complex). If Imag is omitted, it defaults to zero and the function serves as a numeric conversion function like int (), long () and FL Oat (). If Both arguments is omitted, returns 0J.


Note when converting from a string, the string must not contain whitespace around the Central + or-operator. For example, complex (' 1+2j ') was fine, but complex (' 1 + 2j ') raises valueerror.

The complex type is described in Numeric types-int, float, long, complex.


English Description:

Create a complex number with a value of real + imag * J or convert a string or count to plural. If the first argument is a string, you do not need to specify a second argument.


Parameter real:int, long, float or string;

Parameter imag:int, long, float.


>>> Complex (5,3)

(5+3J)

>>> Complex (7)

(7+0J)

>>> complex ("56")

(56+0J)

>>> Complex ("7+8j")

(7+8j)

>>> Complex ("7 + 8j")

Traceback (most recent):

File "<stdin>", line 1, in <module>

Valueerror:complex () arg is a malformed string


This article is from the "Big Cloud Technology" blog, please be sure to keep this source http://hdlptz.blog.51cto.com/12553181/1899528

Python built-in function 3-complex ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.