I have strings of the form Version 1.4.0\\n
and Version 1.15.6\\n
, and I\'d like a simple way of extracting the three numbers from them. I know I
This
a, b, c = (int(i) for i in mystr.split()[1].split('.'))
will give you int
values for a
, b
and c
>>> a
1
>>> b
15
>>> c
6
Depending on how regular or irregular, i.e., consistent, your number/version formats will be, you may want to consider the use of regular expressions, though if they will stay in this format, I would favor the simpler solution if it works for you.