[Solved] Is there a way to return the value of an integer in a list [duplicate]


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]))

solved Is there a way to return the value of an integer in a list [duplicate]