Python chr () explains

So, I'm sure this is a dumb question, but I'm trying to get a deeper understanding of the python chr () function. Also, I wonder if it is always possible to have an integer argument three digits long or only a fixed length for all ascii values?

chr(20) ## '\x14'
chr(020) ## '\x10'

Why does this give me different answers? Does he think β€œ020” is a hex or something else? Also, I am running Python 2.7 on Windows! -Thank!

+4
source share
2 answers

There is nothing to do with char. It is all about numeric literals. And this is cross-language. 0 indicates oct and 0x indicates hex.

print 010 # 8
print 0x10 # 16
+1
source

It makes sense to explain chrand ordtogether.

, Python2 (- Python3 0o ), .

Python2 chr - , 256, , ascii. unichr , 0x10FFFF. ord - , ( ) .

Python3, chr . bytes([v]). ord .

0

All Articles