Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 the next higher character
#1
i have a character as a string of length 1. i want the next higher character. 'a'->'b' or '4'->'5' or '9'->':'. i could do chr(ord(ch)+1). does python have any more elegant way?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#2
#!/usr/bin/python3
import string

for ch in string.ascii_letters:
    print(ch)

Quote
#3
what character does that code yield?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#4
See:
https://docs.python.org/3.7/library/string.html
Quote
#5
You can use a bytearray of length 1, which is a writable array containing a single integer in the range [0, 256). You can use the latin-1 encoding to convert such an array to / from a str instance of length 1 (this is the same as the utf8 encoding for ords below 128).
>>> t = bytearray('a', encoding='latin-1')
>>> t
bytearray(b'a')
>>> t[0] += 5
>>> t
bytearray(b'f')
>>> t.decode('latin-1')
'f'
Quote
#6
Great.
Quote
#7
(Jun-07-2019, 02:33 AM)heiner55 Wrote: See:
https://docs.python.org/3.7/library/string.html

i think you didn't understand my question. i do not see an answer in that link.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#8
Because your question are always very complex.
Quote
#9
if the question is too hard to understand why post any answer at all?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#10
I did not think my answer was so bad.

#!/usr/bin/python3
import string
 
for ch in string.ascii_letters:
    print(ch)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 208 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  finding the next higher representable floating point value Skaperen 0 449 Sep-13-2019, 11:16 PM
Last Post: Skaperen
  Replace changing string including uppercase character with lowercase character silfer 11 1,121 Mar-25-2019, 12:54 PM
Last Post: silfer
  SyntaxError: unexpected character after line continuation character Saka 2 14,085 Sep-26-2017, 09:34 AM
Last Post: Saka
  How do I loop through a list and delete numerical elements that are 1 lower/higher? neko 4 1,590 Sep-05-2017, 02:25 PM
Last Post: ichabod801

Forum Jump:


Users browsing this thread: 1 Guest(s)