为什么int()方法不起作用而字符串没有转换成整数?

时间:2016-11-19 17:30:51

标签: python integer

我有以下代码:

if (sum(L) % 3) == 0:
        biggest_list = []
        for i in range(len(L)):
            biggest_list.append(max(L))
            L.remove(max(L))            
        string_l = []
        for i in range(len(biggest_list)):
            string_l.append(str(biggest_list[i]))                   
        big_word = ''.join(string_l)                    
        big_number = int(big_word)
        v = type(big_number)
        print "big_number (should be number)"
        print t     
        return big_number

为什么big_number变量未转换为整数?以及如何将其转换为整数? 当我运行这段代码时,我的Python 2.7.12 Shell告诉我<type 'str'> 应该<type 'int'>代替。

这是整个功能:

def answer(L):
    if (sum(L) % 3) == 0:
        biggest_list = []
        for i in range(len(L)):
            biggest_list.append(max(L))
            L.remove(max(L))            
        string_l = []
        for i in range(len(biggest_list)):
            string_l.append(str(biggest_list[i]))                   
        big_word = ''.join(string_l)                
        big_number = int(big_word)      
        return big_number

该函数将整数列表作为输入,检查它是否可以被3除,并返回可以由这些整数组成的最大数。

1 个答案:

答案 0 :(得分:0)

I think it's int

我实际上没有得到你的问题