Python function-Complex ()

Source: Internet
Author: User
Complex ([real[, Imag]])

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.

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'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.


code example:

>>> Complex (1, 2) (1 + 2j) #数字 >>> Complex (1) (1 + 0j) #当做字符串处理 >>> Complex ("1") (1 + 0j) #注意: This place is in the "+ "No space on either side, that is, can not be written as" 1 + 2j ", should be" 1+2j ", otherwise will error >>> complex (" 1+2j ") (1 + 2j)
  • 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.