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

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函数示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值