Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- oldstring = '134uu8'
- print 'the initial string is: ', oldstring, '\n'
- # int(oldstring)
- # ValueError: invalid literal for int() with base 10: '134uu8'
- newstring = [x for x in oldstring if x in "0123456789"]
- print 'after list comprehension', newstring
- newstring = "".join(newstring)
- print 'after joining the list strings together', newstring, '\n'
- now_an_int = int(newstring)
- print 'applying int function to the purified string', now_an_int
- print 'and its type is: ', type(now_an_int), '\n\n'
- # import re
- # now_an_int = int(re.sub('[^0-9]', '', oldstring))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement