- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert tuple to float value in Python
When it is required to convert a tuple to a float value, the 'join' method, 'float' method, 'str' method and generator expression can be used.
Generator is a simple way of creating iterators. It automatically implements a class with '__iter__()' and '__next__()' methods and keeps track of the internal states, as well as raises 'StopIteration' exception when no values are present that could be returned.
The 'float' method converts a given element to float data type.
The 'str' method converts the given element into string data type.
Below is a demonstration of the same −
my_tuple_1 = ( 7, 8) print ("The first tuple is : " ) print(my_tuple_1) my_result = float('.'.join(str(elem) for elem in my_tuple_1)) print("After converting the tuple to float, the tuple is : ") print(my_result)
The first tuple is : (7, 8) After converting the tuple to float, the tuple is : 7.8
- A tuple is defined and is displayed on the console.
- The '.' operator and 'join' method is used to join the two elements in the tuple as a decimal number.
- This result is assigned to a variable.
- It is displayed as output on the console.
- How to convert float to integer in Python?
- Convert String to Tuple in Python
- Convert Tuple to integer in Python
- Java Program to convert string value to float using Float.valueOf()
- Convert location coordinates to tuple in Python
- Python program to sort a tuple by its float element
- Python program to convert float decimal to octal number
- How to convert Float array list to float array in Java?
- Convert tuple to adjacent pair dictionary in Python
- Python program to convert Set into Tuple and Tuple into Set
- Convert from float to String in Java
- Convert from String to float in Java
- Convert string to integer/ float in Arduino
- Convert Nested Tuple to Custom Key Dictionary in Python
- Java Program to convert float to String