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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

python中complex函数的用法_Python 内置函数complex详解

發布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中complex函数的用法_Python 内置函数complex详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

英文文檔:

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 "", line 1, in

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 "", line 1, in

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)

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

如您對本文有疑問或者有任何想說的,請點擊進行留言回復,萬千網友為您解惑!

總結

以上是生活随笔為你收集整理的python中complex函数的用法_Python 内置函数complex详解的全部內容,希望文章能夠幫你解決所遇到的問題。

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