python函数示例_带Python示例的complex()函数

本文详细介绍了Python中的complex()函数,该函数用于从实数或虚数生成复数。文章提供了函数的语法、参数说明及返回值,并通过多个示例展示了如何使用此函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

python函数示例

Python complex()函数 (Python complex() function)

complex() function is a library function in Python, it is used to get the complex number from given a real number or/and an imaginary number (which is an optional part), it accepts either a real number only or read and an imaginary number and returns a complex number.

complex()函数是Python中的一个库函数,用于从给定的实数或/和虚数(这是可选部分)中获取复数,它仅接受实数,也可以接受读数和虚数数字并返回一个复数。

Syntax:

句法:

    complex(real [,Imaginary])

Parameter(s):

参数:

  • real – value of a real number

    实数 –实数的值

  • Imaginary – an optional parameter, it's default value is 0.

    虚构 –可选参数,默认值为0。

Return value: complex – it returns a complex type of number containing the value in the form of (real + imaginary*j).

返回值: complex –返回复杂的数字类型,其中包含(real +虚数* j)形式的值。

Example:

例:

    Input:
    real = 10
    img  = 20
        
    print(complex(real))
    print(complex(real, img))
    
    Output:
    (10+0j)
    (10+20j)

Python code to get the complex number

Python代码获取复数

# python code to demonstrate example 
# of complex() function

real = 10
img  = 20

# complex number  by passing real number
print(complex(real))

# complex number  by passing real & img. number
print(complex(real, img))

# complex number by passing real part as 0
print(complex(0))

# complex number by passing real and img. part as 0, 0
print(complex(0,0))

# with float values
real = 10.23
img  = 20.45

# complex number  by passing real number
print(complex(real))

# complex number  by passing real & img. number
print(complex(real, img))

Output

输出量

(10+0j)
(10+20j)
0j
0j
(10.23+0j)
(10.23+20.45j)


翻译自: https://www.includehelp.com/python/complex-function-with-example.aspx

python函数示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值