Is there any function that can convert a tuple into an integer?
Example:
input = (1, 3, 7)
output = 137
Using the tuple() built-in function An iterable can be passed as an input to the tuple () function, which will convert it to a tuple object. If you want to convert a Python list to a tuple, you can use the tuple() function to pass the full list as an argument, and it will return the tuple data type as an output.
To convert a string to integer in Python, use the int() function. This function takes two parameters: the initial string and the optional base to represent the data. Use the syntax print(int("STR")) to return the str as an int , or integer.
Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable as it also is called.
>>> reduce(lambda rst, d: rst * 10 + d, (1, 2, 3))
123
>>> x = (1,3,7)
>>> int(''.join(map(str,x)))
137
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With