number = '9-11'
number1 = '10-30'
In Python, how do I print only the values in front of it, and the values in the back? However, since the units of numbers are different like 9 and 10, it is not extracted as a position value, but
Is there a way to extract the number before the '-' from 9-11, or the number after the '-
I tried typing "*-" like Excel, but it didn't work.T
I ask for your help me.
slice
>>> "9-11".split("-")
['9', '11']
>>> [ int(s) for s in "9-11".split("-") ]
[9, 11]
>>> map(int, "9-11".split("-"))
<map object at 0x00000289A41F44C0>
>>> tuple(map(int, "9-11".split("-")))
(9, 11)
>>> tuple(map(int, "10-30".split("-")))
(10, 30)
>>> tuple(map(int, "1-2-3-4-30".split("-")))
(1, 2, 3, 4, 30)
>>>
Thank you so much for your answer. There's no place to ask I was struggling by myself and cried. I'll deal with it bravely from now on. ^ Thanks once again.
^
© 2024 OneMinuteCode. All rights reserved.