View difference between Paste ID: 85JgJDrC and 8PWRuZC3
SHOW: | | - or go back to the newest paste.
1
oldstring = '134uu8'
2
print 'the initial string is: ', oldstring, '\n'
3
# int(oldstring)
4
# ValueError: invalid literal for int() with base 10: '134uu8'
5
6
newstring = [x for x in oldstring if x in "0123456789"]
7
print 'after list comprehension', newstring
8
newstring = "".join(newstring)
9
print 'after joining the list strings together', newstring, '\n'
10
now_an_int = int(newstring)
11
print 'applying int function to the purified string', now_an_int
12
print 'and its type is: ', type(now_an_int), '\n\n'
13-
print 'and its type is: ', type(now_an_int), '\n\n'
13+
14
15
# import re
16
# now_an_int = int(re.sub('[^0-9]', '', oldstring))