+ 1

A little help for my brian. How to change a string (0-9 & a-z & A-Z) to char. Maybe a small example please.

i.e. str_x = ('01246abreDwegbS') how to get the (ord <--> chr) for every stringelement? my Brian sucks at the moment :-( ... maybe i'am a little drunk

13th Nov 2017, 10:52 PM
Da Riebi
Da Riebi - avatar
4 Antworten
+ 3
The ord() and chr() functions are the inverse of each other. Where the ord() function takes a single unicode character as a string and returns the decimal integer value of that character and the chr() function would take in that integer value and return the single unicode character as a string. https://docs.python.org/3.6/library/functions.html#ord https://docs.python.org/3.6/library/functions.html#chr https://unicode-table.com/en/#control-character You could print the ord value of each of the characters in your string by: [print(ord(value)) for value in '01246abreDwegbS']
14th Nov 2017, 3:50 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Char's (character's) don't exist in python. They're Strings, and Python will only see them that way, even if you have a single character in them. So to answer your question (sort of, places them all as individual strings lol): example = "abcdefg1234ABCDEFG_99100" print([char for char in example])
14th Nov 2017, 12:42 AM
Sapphire
+ 1
thanks for your answers :-)
14th Nov 2017, 5:09 AM
Da Riebi
Da Riebi - avatar
+ 1
i got it :-) thanks to you again https://code.sololearn.com/cRssX0mNtLX7/?ref=app
14th Nov 2017, 11:35 AM
Da Riebi
Da Riebi - avatar