Language/Python
Python - chr(), 전달받은 정수를 ASCII character로 변환하는 함수
TechNote.kr
2017. 12. 29. 14:04
728x90
chr
>>> chr(i)
전달받은 정수(integer, 0 ~ 255)를 ASCII character로 변환한다.
__builtin__ module에 포함된 function 이다.
예)
정수(integer, 0 ~ 255)를 넘겨주었을 경우
>>> chr(0) '\x00' >>> chr(10) '\n' >>> chr(97) 'a'
0 ~ 255 범위를 넘는 정수를 넘겨주었을 경우
>>> chr(300) Traceback (most recent call last): File "", line 1, in ValueError: chr() arg not in range(256)
실수(float)를 넘겨주었을 경우
>>> chr(1.7) Traceback (most recent call last): File "", line 1, in TypeError: integer argument expected, got float
문자(character)를 넘겨주었을 경우
>>> chr('a') Traceback (most recent call last): File "", line 1, in TypeError: an integer is required
>>> help(chr)
Help on built-in function chr in module __builtin__:
chr(...)
chr(i) -> character
Return a string of one character with ordinal i; 0 <= i < 256.
728x90