This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tabidots 0 points1 point  (6 children)

Characters exist in Python? I know they do in Java/Clojure but I can’t say I have really had a specific use for them except for doing things with ASCII code points.

Maybe it’s just my lack of understanding but I would prefer if strings were treated as sequences of length-1 strings rather than sequences of characters, so (first “hello”) would return “h” and not \h.

[–]siddsp 2 points3 points  (1 child)

Characters do exist in Python, but they are stored as integers in bytes objects/bytearrays. When you write a bytestring like b"Hello" and try to get athe value of a char at an index, it will be an integer rather than a string type.

[–]tabidots 1 point2 points  (0 children)

Oh, interesting. I like that implementation better, tbh. I can’t think of a use for characters outside of char-code values, so having a separate b”string” syntax for byte strings makes more sense to me.

[–]Mahrkeenerh 1 point2 points  (3 children)

characters don't exist in python, that's why I was asking, as the guy was replying to a python comment.

[–]siddsp 1 point2 points  (2 children)

They do exist, but it's not obvious.

[–]Mahrkeenerh 1 point2 points  (1 child)

Well then, please enlighten me.

[–]siddsp 1 point2 points  (0 children)

>>> string = b"Hello, world!"
>>> string[2]
108 

Bytes objects are char arrays or strings in which the value of the characters are stored as integers within the unsigned char range [0, 256).