-5
proId = 'nam001'

I want to increment numeric values only. That should be like this 'nam002', 'nam003'. How to do this?

Adam.Er8
  • 12,675
  • 3
  • 26
  • 38
user3030327
  • 411
  • 1
  • 7
  • 19

1 Answers1

1

Just because you asked nicely :D

You can use the simplest for loop, with str.zfill to pad with zeroes, then add it to the 'nam' prefix like this:

for i in range(1,11):
    proId = 'nam' + str(i).zfill(3)
    print(proId) # or do whatever you need with it...

Output:

nam001
nam002
...
nam009
nam010
Adam.Er8
  • 12,675
  • 3
  • 26
  • 38