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,并将此作为返回值。
有兴趣可以试试看下面