Python functions-complex ()

Source: Internet
Author: User
Python functions-complex () complex ([real [, imag])

Chinese description:

Create a plural value of real + imag * j or convert a string or number to a plural value. If the first parameter is a string, you do not need to specify the second parameter.

Parameter real: int, long, float or string;

Parameter imag: int, long, float.

English description:

Create a complex number with the value real + imag * j or convert a string or number to a complex number. if the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. the second parameter can never be a string. each argument may be 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 float (). if both arguments are 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') is fine, but complex ('1 + 2j') raises ValueError.

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


Code example:

>>> Complex (1, 2) (1 + 2j) # number >>>> complex (1) (1 + 0j) # processing as a string >>> complex ("1") (1 + 0j) # Note: there cannot be spaces on either side of the "+, that is, it cannot be written as "1 + 2j". it should be "1 + 2j". Otherwise, an error will be reported >>> complex ("1 + 2j") (1 + 2j)

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.