Home  >  Article  >  Backend Development  >  What does complex mean in python?

What does complex mean in python?

尚
Original
2020-01-09 09:23:4118156browse

What does complex mean in python?

complex() function is used to create a complex number with a value of real imag * j or to convert a string or number into a complex number. If the first parameter is a string, there is no need to specify the second parameter. (Recommended: Python Programming Video)

Grammar

complex Grammar:

class complex([real[, imag]])

Parameter description:

real -- int, long, float or string;

imag -- int, long, float;

Return value

Returns a complex number.

Examples

The following examples demonstrate the use of complex:

>>>complex(1, 2)
(1 + 2j)
 
>>> complex(1)    # 数字
(1 + 0j)
 
>>> complex("1")  # 当做字符串处理
(1 + 0j)
 
# 注意:这个地方在"+"号两边不能有空格,也就是不能写成"1 + 2j",应该是"1+2j",否则会报错
>>> complex("1+2j")
(1 + 2j)

The above is the detailed content of What does complex mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use subplotNext article:How to use subplot