I need to extract a two digit number from a string in python3.
** e.g. string is "1234" and I want the middle two numbers so I get 23.**
This isn't limited to just four letters, it could be hundreds.
Please could someone help?
Thank you as always!
To extract two digits from the string "1234"
str function can be used.
Code:
stringparse="1234"
twodigit= stringparse[1]+stringparse[2]
print(twodigit)
Output Out[180]: '23'
According to a quick Google search (this website), you should do:
String = "1234"
ChoppedString = String[1:3] #Remember, the first letter is 0, the second is 1, etc.
print(ChoppedString)
The [1:3] bit just means 'Start at the first letter, then get everything up to (but excluding) the second one.
12345?'1234567'?