Python convert Tuple to Integer

前端 未结 8 681
心在旅途
心在旅途 2021-01-02 03:10

Is there any function that can convert a tuple into an integer?

Example:

input = (1, 3, 7)

output = 137
8条回答
  •  一个人的身影
    2021-01-02 03:44

    The simplest method to change a tuple into a number is to use string formating.

    input = (1, 3, 7)
    output = int('{}{}{}'.format(input[0], input[1], input[2]))
    
    # TEST
    print(output) # 137
    print(type(output)) # 
    

提交回复
热议问题