Python complex() 函数

Python 教程 · 2019-02-01 16:27:46

描述

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 教程 文章: https://codercto.com/courses/l/8.html

查看所有标签

JavaScript & jQuery

JavaScript & jQuery

David Sawyer McFarland / O Reilly / 2011-10-28 / USD 39.99

You don't need programming experience to add interactive and visual effects to your web pages with JavaScript. This Missing Manual shows you how the jQuery library makes JavaScript programming fun, ea......一起来看看 《JavaScript & jQuery》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具