“Python func complex”的版本间差异

本页内容
上一节: Python_func_import 下一节: Python_func_hasattr
(创建页面,内容为“{{DISPLAYTITLE:complex(real [,imag])}}3 = Python complex() 函数 = Python 内置函数 == 描述 == '''complex()''' 函数用于创建一个值为 real + imag * j 的复数或者转化一个字符串或数为复数。如果第一个参数为字符串,则不需要指定第二个参数。。 == 语法 == complex 语法: <sample title="" desc="" lang="python" hererun="1"> class complex([real[,…”)
 
Neo讨论 | 贡献
无编辑摘要
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
{{DISPLAYTITLE:complex(real [,imag])}}[[Category:python3 data type|3]]
{{DISPLAYTITLE:complex()}}[[Category:python3 built in functions|60]]
= Python complex() 函数 =
= Python complex() 函数 =


第26行: 第26行:
以下实例展示了 complex 的使用方法:
以下实例展示了 complex 的使用方法:


<sample title="" desc="" lang="python" hererun="1">  
<sample title="" desc="" lang="python" hererun="1">
>>>complex(1, 2)
>>>complex(1, 2)
(1 + 2j)
(1 + 2j)
第39行: 第39行:
>>> complex("1+2j")
>>> complex("1+2j")
(1 + 2j)
(1 + 2j)
  </sample>
</sample>
[[python built in functions|Python 内置函数]]
[[python built in functions|Python 内置函数]]

2022年8月17日 (三) 21:50的最新版本

Python complex() 函数

Python 内置函数

描述

complex() 函数用于创建一个值为 real + imag * j 的复数或者转化一个字符串或数为复数。如果第一个参数为字符串,则不需要指定第二个参数。。

语法

complex 语法:


示例

class complex([real[, imag]])

参数说明:

  • real -- int, long, float或字符串;
  • imag -- int, long, float;

返回值

返回一个复数。

以下实例展示了 complex 的使用方法:


示例

>>>complex(1, 2)
(1 + 2j)

>>> complex(1)    # 数字
(1 + 0j)

>>> complex("1")  # 当做字符串处理
(1 + 0j)

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

Python 内置函数

上一节: Python_func_import 下一节: Python_func_hasattr
此页面最后编辑于2022年8月17日 (星期三) 21:50。