Trying to return an integer of an item from a list of values. For example
after splitting Hotdog : 3.00
with .split()
I get
['Hotdog', ':', '3.00']
What can I do to return the '3.00'
?
thanks
Trying to return an integer of an item from a list of values. For example
after splitting Hotdog : 3.00
with .split()
I get
['Hotdog', ':', '3.00']
What can I do to return the '3.00'
?
thanks
You can access it
by knowing it's exact position
str_val = "Hotdog : 3.00".split()[2]
by knowing it's last item
str_val = "Hotdog : 3.00".split()[-1]
To get it as a number
# as float
val = float("Hotdog : 3.00".split()[2])
# as int, you need intermediate float as '3.00' is not direct int
val = int(float("Hotdog : 3.00".split()[2]))