goodthings4me.tistory.com
■ 파이썬으로 ASCII Code 출력하기
cnt = 0
for n in range(256):
cnt += 1
print('{0:>3}:{1:>6}'.format(n, repr(chr(n))), end = '\t')
if cnt % 4 == 0:
print()
[실행 결과]
0:'\x00' 1:'\x01' 2:'\x02' 3:'\x03'
4:'\x04' 5:'\x05' 6:'\x06' 7:'\x07'
8:'\x08' 9: '\t' 10: '\n' 11:'\x0b'
12:'\x0c' 13: '\r' 14:'\x0e' 15:'\x0f'
16:'\x10' 17:'\x11' 18:'\x12' 19:'\x13'
20:'\x14' 21:'\x15' 22:'\x16' 23:'\x17'
24:'\x18' 25:'\x19' 26:'\x1a' 27:'\x1b'
28:'\x1c' 29:'\x1d' 30:'\x1e' 31:'\x1f'
32: ' ' 33: '!' 34: '"' 35: '#'
36: '$' 37: '%' 38: '&' 39: "'"
40: '(' 41: ')' 42: '*' 43: '+'
44: ',' 45: '-' 46: '.' 47: '/'
48: '0' 49: '1' 50: '2' 51: '3'
52: '4' 53: '5' 54: '6' 55: '7'
56: '8' 57: '9' 58: ':' 59: ';'
60: '<' 61: '=' 62: '>' 63: '?'
64: '@' 65: 'A' 66: 'B' 67: 'C'
68: 'D' 69: 'E' 70: 'F' 71: 'G'
72: 'H' 73: 'I' 74: 'J' 75: 'K'
76: 'L' 77: 'M' 78: 'N' 79: 'O'
80: 'P' 81: 'Q' 82: 'R' 83: 'S'
84: 'T' 85: 'U' 86: 'V' 87: 'W'
88: 'X' 89: 'Y' 90: 'Z' 91: '['
92: '\\' 93: ']' 94: '^' 95: '_'
96: '`' 97: 'a' 98: 'b' 99: 'c'
100: 'd' 101: 'e' 102: 'f' 103: 'g'
104: 'h' 105: 'i' 106: 'j' 107: 'k'
108: 'l' 109: 'm' 110: 'n' 111: 'o'
112: 'p' 113: 'q' 114: 'r' 115: 's'
116: 't' 117: 'u' 118: 'v' 119: 'w'
120: 'x' 121: 'y' 122: 'z' 123: '{'
124: '|' 125: '}' 126: '~' 127:'\x7f'
128:'\x80' 129:'\x81' 130:'\x82' 131:'\x83'
132:'\x84' 133:'\x85' 134:'\x86' 135:'\x87'
136:'\x88' 137:'\x89' 138:'\x8a' 139:'\x8b'
140:'\x8c' 141:'\x8d' 142:'\x8e' 143:'\x8f'
144:'\x90' 145:'\x91' 146:'\x92' 147:'\x93'
148:'\x94' 149:'\x95' 150:'\x96' 151:'\x97'
152:'\x98' 153:'\x99' 154:'\x9a' 155:'\x9b'
156:'\x9c' 157:'\x9d' 158:'\x9e' 159:'\x9f'
160:'\xa0' 161: '¡' 162: '¢' 163: '£'
164: '¤' 165: '¥' 166: '¦' 167: '§'
168: '¨' 169: '©' 170: 'ª' 171: '«'
172: '¬' 173:'\xad' 174: '®' 175: '¯'
176: '°' 177: '±' 178: '²' 179: '³'
180: '´' 181: 'µ' 182: '¶' 183: '·'
184: '¸' 185: '¹' 186: 'º' 187: '»'
188: '¼' 189: '½' 190: '¾' 191: '¿'
192: 'À' 193: 'Á' 194: 'Â' 195: 'Ã'
196: 'Ä' 197: 'Å' 198: 'Æ' 199: 'Ç'
200: 'È' 201: 'É' 202: 'Ê' 203: 'Ë'
204: 'Ì' 205: 'Í' 206: 'Î' 207: 'Ï'
208: 'Ð' 209: 'Ñ' 210: 'Ò' 211: 'Ó'
212: 'Ô' 213: 'Õ' 214: 'Ö' 215: '×'
216: 'Ø' 217: 'Ù' 218: 'Ú' 219: 'Û'
220: 'Ü' 221: 'Ý' 222: 'Þ' 223: 'ß'
224: 'à' 225: 'á' 226: 'â' 227: 'ã'
228: 'ä' 229: 'å' 230: 'æ' 231: 'ç'
232: 'è' 233: 'é' 234: 'ê' 235: 'ë'
236: 'ì' 237: 'í' 238: 'î' 239: 'ï'
240: 'ð' 241: 'ñ' 242: 'ò' 243: 'ó'
244: 'ô' 245: 'õ' 246: 'ö' 247: '÷'
248: 'ø' 249: 'ù' 250: 'ú' 251: 'û'
252: 'ü' 253: 'ý' 254: 'þ' 255: 'ÿ'
■ 영문 대소문자에 대한 ASCII코드와 2, 8, 16진수 값
for n in range(65, 123):
if n in(range(91, 97)):
continue
if n == 97:
print()
print('{:>2} {:>3} {:>10} {:>6} {:>6}'.format(chr(n), n, bin(n), oct(n), hex(n)))
[실행 결과]
A 65 0b1000001 0o101 0x41
B 66 0b1000010 0o102 0x42
C 67 0b1000011 0o103 0x43
D 68 0b1000100 0o104 0x44
E 69 0b1000101 0o105 0x45
F 70 0b1000110 0o106 0x46
G 71 0b1000111 0o107 0x47
H 72 0b1001000 0o110 0x48
I 73 0b1001001 0o111 0x49
J 74 0b1001010 0o112 0x4a
K 75 0b1001011 0o113 0x4b
L 76 0b1001100 0o114 0x4c
M 77 0b1001101 0o115 0x4d
N 78 0b1001110 0o116 0x4e
O 79 0b1001111 0o117 0x4f
P 80 0b1010000 0o120 0x50
Q 81 0b1010001 0o121 0x51
R 82 0b1010010 0o122 0x52
S 83 0b1010011 0o123 0x53
T 84 0b1010100 0o124 0x54
U 85 0b1010101 0o125 0x55
V 86 0b1010110 0o126 0x56
W 87 0b1010111 0o127 0x57
X 88 0b1011000 0o130 0x58
Y 89 0b1011001 0o131 0x59
Z 90 0b1011010 0o132 0x5a
a 97 0b1100001 0o141 0x61
b 98 0b1100010 0o142 0x62
c 99 0b1100011 0o143 0x63
d 100 0b1100100 0o144 0x64
e 101 0b1100101 0o145 0x65
f 102 0b1100110 0o146 0x66
g 103 0b1100111 0o147 0x67
h 104 0b1101000 0o150 0x68
i 105 0b1101001 0o151 0x69
j 106 0b1101010 0o152 0x6a
k 107 0b1101011 0o153 0x6b
l 108 0b1101100 0o154 0x6c
m 109 0b1101101 0o155 0x6d
n 110 0b1101110 0o156 0x6e
o 111 0b1101111 0o157 0x6f
p 112 0b1110000 0o160 0x70
q 113 0b1110001 0o161 0x71
r 114 0b1110010 0o162 0x72
s 115 0b1110011 0o163 0x73
t 116 0b1110100 0o164 0x74
u 117 0b1110101 0o165 0x75
v 118 0b1110110 0o166 0x76
w 119 0b1110111 0o167 0x77
x 120 0b1111000 0o170 0x78
y 121 0b1111001 0o171 0x79
z 122 0b1111010 0o172 0x7a
■ 숫자와 진수(2, 8, 16) 중 하나의 진수를 인자로 받아 해당 진수 값을 리턴
def calc_numeration(decimal, sel):
sel = str(sel)
return {
'2': bin(decimal),
'8': oct(decimal),
'16': hex(decimal)
}.get(sel)
res = calc_numeration(2020, 16)
print(res)
[실행 결과]
0x7e4
'코딩 연습 > 코딩배우기' 카테고리의 다른 글
파이썬의 일급 객체 함수 개념을 이용한 클로저(closure) 연습 (0) | 2020.11.10 |
---|---|
파이썬 크롤링(Crawling) - 셀레니움(Selenium) 연습 #1 (0) | 2020.11.09 |
파이썬 크롤링(Crawling) 연습 - BeautifulSoup Documentation #2 (find_all, find, select 등) (0) | 2020.11.08 |
파이썬 크롤링(Crawling) 연습 - BeautifulSoup Documentation #1 (html 태그로 접근, 객체 4종류 등) (0) | 2020.11.07 |
파이썬 크롤링(Crawling) 연습 - 네이버 영화 평점/리뷰, 영화코드 추출 (0) | 2020.11.04 |
댓글