Q:

Python program to convert tuple to float value

belongs to collection: Python Tuple Programs

0

Example:

tuple = ("python", "includehelp", 43, 54.23)

Converting Tuple elements to Float Value

In this article, we are given a tuple consisting of two elements. Our task is to create a Python program to convert the elements of the tuple to a float value.

Input:
(5, 1)

Output:
5.1

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

We will loop over the tuple and use the str() method to convert the elements to string with are joined using the join() method and finally the float() method performs the final conversion.

# Python program to convert tuple 
# to a float value

# Initializing and printing the tuple 
myTuple = (7356, 67584)
print("The elements of the tuple are " + str(myTuple))

# converting tuple to float
floatVal = float('.'.join(str(value) for value in myTuple))

# Printing result
print("The converted float value is " + str(floatVal))

Output:

The elements of the tuple are (7356, 67584)
The converted float value is 7356.67584

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Tuple Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program to concatenate tuples to nested tup... >>
<< Python program to perform the addition of nested t...