解决complex转int的问题

Gelsey ·
更新时间:2024-09-20
· 951 次阅读

解决complex转int的问题 代码 错误 int(666j)

Traceback (most recent call last):
File “”, line 1, in
int(999j)
TypeError: can’t convert complex to int

正确 def complextoint(cp): cp = list(str(cp)) #从complex转str再转list cp.remove(j) #去掉尾部的j j = "" #创造空字符串变量j for i in cp: #遍历列表 j += i return int(j) #最后由str转int,并将此作为返回值。

有兴趣可以试试看下面



int

需要 登录 后方可回复, 如果你还没有账号请 注册新账号