1

I have a variable which holds a letter. In order to have a concrete example let's assume it is 'A'. I have a while loop which on certain conditions will change that variable to the next letter ('B' in this case).

I would like to know how to achieve that in python:

Pseudocode:
char = 'A'
next_char = 'A' + 1


Python:
letter = 'A'
next_letter = 'A' + 1 # This fails with error TypeError: can only concatenate str (not "int") to str
M.E.
  • 4,955
  • 4
  • 49
  • 128

1 Answers1

1
letter = 'A'
next_letter = chr(ord(letter) + 1)
Moormanly
  • 1,258
  • 1
  • 9
  • 20