Home > Backend Development > Python Tutorial > What does complex mean in python?

What does complex mean in python?

Release: 2020-01-09 09:23:41
Original
18243 people have browsed it

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]])
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template