国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python 內置函數complex詳解

2020-01-04 17:22:26
字體:
來源:轉載
供稿:網友

英文文檔:

class complex([real[, imag]])

Return a complex number with the value real + imag*1j or convert a string or number to a complex number. If the first parameter is a string, it will be interpreted as a complex number and the function must be called without a second parameter. The second parameter can never be a string. Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the constructor serves as a numeric conversion like int and float. If both arguments are omitted, returns 0j.

Note

When converting from a string, the string must not contain whitespace around the central + or - operator. For example, complex('1+2j') is fine, but complex('1 + 2j') raises ValueError.

說明:

  1. 函數功能,返回一個復數。有兩個可選參數。

  2. 當兩個參數都不提供時,返回復數 0j。

>>> complex()0j 

  3. 當第一個參數為字符串時,調用時不能提供第二個參數。此時字符串參數,需是一個能表示復數的字符串,而且加號或者減號左右不能出現空格。

>>> complex('1+2j',2) #第一個參數為字符串,不能接受第二個參數Traceback (most recent call last): File "<pyshell#2>", line 1, in <module>  complex('1+2j',2)TypeError: complex() can't take second arg if first is a string>>> complex('1 + 2j') #不能有空格Traceback (most recent call last): File "<pyshell#3>", line 1, in <module>  complex('1 + 2j')ValueError: complex() arg is a malformed string

   4. 當第一個參數為int或者float時,第二個參數可為空,表示虛部為0;如果提供第二個參數,第二個參數也需為int或者float。

>>> complex(2)(2+0j)>>> complex(2.1,-3.4)(2.1-3.4j) 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐业县| 芒康县| 金寨县| 二手房| 丰原市| 蒙阴县| 华容县| 泽库县| 奇台县| 酉阳| 尚义县| 旌德县| 广灵县| 根河市| 凌海市| 赫章县| 潞城市| 武汉市| 鹤岗市| 德阳市| 满洲里市| 兴安盟| 平顶山市| 墨玉县| 无锡市| 海门市| 铜鼓县| 科技| 长治县| 胶南市| 湖州市| 襄城县| 九龙县| 泾阳县| 凤庆县| 德州市| 大荔县| 龙泉市| 新源县| 朝阳县| 青岛市|