Python | Convert tuple to float value Last Updated : 23 Apr, 2023 Comments Improve Suggest changes Like Article Like Report Sometimes, while working with tuple, we can have a problem in which, we need to convert a tuple to floating-point number in which first element represents integer part and next element represents a decimal part. Let's discuss certain way in which this can be achieved. Method : Using join() + float() + str() + generator expression The combination of above functionalities can solve this problem. In this, we 1st convert the tuple elements into a string, then join them and convert them to desired integer. Python3 # Python3 code to demonstrate working of # Convert tuple to float # using join() + float() + str() + generator expression # initialize tuple test_tup = (4, 56) # printing original tuple print("The original tuple : " + str(test_tup)) # Convert tuple to float # using join() + float() + str() + generator expression res = float('.'.join(str(ele) for ele in test_tup)) # printing result print("The float after conversion from tuple is : " + str(res)) OutputThe original tuple : (4, 56) The float after conversion from tuple is : 4.56 Method #2 : Using format() + join()This method is similar to the above method but instead of using generator expression, we use the join() function with format() method to convert the tuple elements into a string. Python3 # Python3 code to demonstrate working of # Convert tuple to float # using format() + join() # initialize tuple test_tup = (4, 56) # printing original tuple print("The original tuple : " + str(test_tup)) # Convert tuple to float # using format() + join() res = float("{}.{}".format(*test_tup)) # printing result print("The float after conversion from tuple is : " + str(res)) #This code is contributed by Edula Vinay Kumar Reddy OutputThe original tuple : (4, 56) The float after conversion from tuple is : 4.56 Time complexity : O(1)Auxiliary Space : O(1) Method #3: Using math and tuple unpacking Import the math moduleUnpack the tuple into separate variables using tuple unpackingDivide the first element by 10^d, where d is the number of digits in the second elementAdd the quotient from step 3 to the second element, to get a float Python3 import math # initialize tuple test_tup = (4, 56) # printing original tuple print("The original tuple : " + str(test_tup)) # Convert tuple to float using math and tuple unpacking a, b = test_tup res = a + (b / math.pow(10, len(str(b)))) # round the result to 2 decimal places res = round(res, 2) # printing result print("The float after conversion from tuple is : " + str(res)) OutputThe original tuple : (4, 56) The float after conversion from tuple is : 4.56 Time complexity: O(1)Auxiliary space: O(1) Comment More infoAdvertise with us Next Article Python | Convert tuple to float value manjeet_04 Follow Improve Article Tags : Python Python Programs Python tuple-programs Practice Tags : python Similar Reads Convert List to Tuple in Python The task of converting a list to a tuple in Python involves transforming a mutable data structure list into an immutable one tuple. Using tuple()The most straightforward and efficient method to convert a list into a tuple is by using the built-in tuple(). This method directly takes any iterable like 2 min read Python | Convert Tuple to integer Sometimes, while working with records, we can have a problem in which we need to convert the data records to integer by joining them. Let's discuss certain ways in which this task can be performed. Method #1 : Using reduce() + lambda The combination of above functions can be used to perform this tas 5 min read Convert Float String List to Float Values-Python The task of converting a list of float strings to float values in Python involves changing the elements of the list, which are originally represented as strings, into their corresponding float data type. For example, given a list a = ['87.6', '454.6', '9.34', '23', '12.3'], the goal is to convert ea 3 min read Python | Convert location coordinates to tuple Sometimes, while working with locations, we need a lot of data which has location points in form of latitudes and longitudes. These can be in form of a string and we desire to get tuple versions of same. Let's discuss certain ways in which this task can be performed. Method #1 : Using tuple() + floa 4 min read Python - Convert Tuple String to Integer Tuple Interconversion of data is a popular problem developer generally deal with. One can face a problem to convert tuple string to integer tuple. Let's discuss certain ways in which this task can be performed. Method #1 : Using tuple() + int() + replace() + split() The combination of above methods can be 7 min read Convert String to Tuple - Python When we want to break down a string into its individual characters and store each character as an element in a tuple, we can use the tuple() function directly on the string. Strings in Python are iterable, which means that when we pass a string to the tuple() function, it iterates over each characte 2 min read Convert Tuple to Json Array in Python Python's versatility as a programming language extends to its rich data structures, including tuples and JSON. JSON, abbreviation for JavaScript Object Notation, is a lightweight data format used for representing structured data. Moreover, it is a syntax for storing and exchanging data. In this arti 3 min read Python - Change Datatype of Tuple Values Sometimes, while working with set of records, we can have a problem in which we need to perform a data type change of values of tuples, which are in its 2nd position, i.e value position. This kind of problem can occur in all domains that include data manipulations. Let's discuss certain ways in whic 3 min read Python - Convert Binary tuple to Integer Given Binary Tuple representing binary representation of a number, convert to integer. Input : test_tup = (1, 1, 0) Output : 6 Explanation : 4 + 2 = 6. Input : test_tup = (1, 1, 1) Output : 7 Explanation : 4 + 2 + 1 = 7. Method #1 : Using join() + list comprehension + int() In this, we concatenate t 5 min read Convert Floating to Binary - Python The task of converting a floating-point number to its binary representation in Python involves representing the number in the IEEE 754 format, which consists of a sign bit, an exponent and a mantissa. For example, given the floating-point number 10.75, its IEEE 754 32-bit binary representation is "0 3 min read Like