日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python 内建函数 - complex([real[, imag]])

發布時間:2024/1/8 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python 内建函数 - complex([real[, imag]]) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  • Manual
  • 直譯
  • 實例
  • 拓展閱讀

Manual

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.

The complex type is described in Numeric Types — int, float, complex.

直譯

以實部+虛部*1j形式返回一個復數,或將字符串或數字轉化為復數。如果第一個參數是字符串,它將會被轉化為復數,且函數的調用不能有第二個參數,第二個參數永遠不能是字符串。每個參數可以使任意數值類型(包括復數)。如果缺省虛部,它默認為0,構造器會以整數或浮點數值進行對待。如果兩個參數都缺省,則返回0j。

注意:當從一個字符串轉化時,字符串在中間的‘+’或‘-’操作符周圍不能包含空格。例如:復數complex('1+2j')可行,但complex('1 + 2j')則會引發ValueError。

復數類型詳見數值類型—整數,浮點數和復數

實例

>>> complex(0) 0j >>> complex(3, 5) (3+5j) >>> complex(2.25, 163.33) (2.25+163.33j) >>> complex('1+2j') (1+2j) >>> complex('1 + 2j') Traceback (most recent call last):File "<pyshell#144>", line 1, in <module>complex('1 + 2j') ValueError: complex() arg is a malformed string >>> complex('1+2j', '6j') Traceback (most recent call last):File "<pyshell#145>", line 1, in <module>complex('1+2j', '6j') TypeError: complex() can't take second arg if first is a string

拓展閱讀

數值類型—整數,浮點數和復數

總結

以上是生活随笔為你收集整理的Python 内建函数 - complex([real[, imag]])的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。