-2

For a number that is 32,146 ...how do I find only 146? Is this able to be done?

findnum = '32,146'
return findnum
Dzrte4gle
  • 49
  • 5

3 Answers3

4

Work with split

>>> findnum = '32,146'
>>> findnum.split(',')
['32', '146']
Andrea Corbellini
  • 17,339
  • 3
  • 53
  • 69
rafaelc
  • 57,686
  • 15
  • 58
  • 82
1

If you want the number you can do:

# get number by ignoring commas
number = int(findnum.replace(',',''))

# get last three digits
last_three = number % 1000

This will result in 146 (int) and not '146' (string)

Example:

>>> findnum = '32,146'
>>> number = int(findnum.replace(',',''))
>>> number % 1000
146
Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88
-1

Since its a string and not a number:

Can use slicing after the ',' to the end:

s[s.index(',')+1:]
chenchuk
  • 5,324
  • 4
  • 34
  • 41