Advertisement
user_137

string to int (complex)

Feb 15th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1.  
  2. oldstring = '134uu8'
  3. print 'the initial string is: ', oldstring, '\n'
  4. # int(oldstring)
  5. # ValueError: invalid literal for int() with base 10: '134uu8'
  6.  
  7. newstring = [x for x in oldstring if x in "0123456789"]
  8. print 'after list comprehension', newstring
  9. newstring = "".join(newstring)
  10. print 'after joining the list strings together', newstring, '\n'
  11. now_an_int = int(newstring)
  12. print 'applying int function to the purified string', now_an_int
  13. print 'and its type is: ', type(now_an_int), '\n\n'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement