How to Convert tuple to float value in python - Handy Hack
Many times, When we working with tuple, we have faced a problem in which we need to convert a tuple to floating point number. In a tuple first element represents integer part and next element represents a decimal part. Now the problem is - How to Convert tuple to float value? Let's discuss the creation way-
Main Method: Using join() + float() + str() + generator expression
Using this method we just convert first tuple element into a string, and then join them and convert them to desire integer.
Source Code:
# Convert tuple to float
# using join() + float() + str() + generator expression
#initialize tuple
tuple = (9,12)
#printing original tuple
print("The original tuple: " + str(tuple))
# Convert tuple to float
# using join() + float() + str() + generator expression
var = float(' . ' . join(str(ele) for ele in tuple))
#print result
print("The float number after conversion from tuple is : " + str(var))
Output:
The original tuple: (9,12)
The float number after conversion from tuple is : 9.12
Note:
1. Concatenate a list of strings into one string: join()
2. Concatenate a list of numbers into one string: join(), str()
Main Method: Using join() + float() + str() + generator expression
Using this method we just convert first tuple element into a string, and then join them and convert them to desire integer.
Source Code:
# Convert tuple to float
# using join() + float() + str() + generator expression
#initialize tuple
tuple = (9,12)
#printing original tuple
print("The original tuple: " + str(tuple))
# Convert tuple to float
# using join() + float() + str() + generator expression
var = float(' . ' . join(str(ele) for ele in tuple))
#print result
print("The float number after conversion from tuple is : " + str(var))
Output:
The original tuple: (9,12)
The float number after conversion from tuple is : 9.12
Note:
1. Concatenate a list of strings into one string: join()
2. Concatenate a list of numbers into one string: join(), str()
Subscribe to:
Post Comments
(
Atom
)
Borgata Hotel Casino & Spa - Black Hawk, CO - Argadar
ReplyDeleteBlack Hawk Casino kargadanco.com Resort is a 라이브바카라 casino hotel, located in Black 꽁머니 토토 Hawk, 강원랜드 Colorado. In addition to the casino itself, the 비윈티비 casino is also