1. 아스키 10진수

In [19]: chr(65)
Out[19]: 'A'

In [1]: ord('A')
Out[1]: 65

2. 아스키 헥사
\x()() 형태로 \x 다음 2자리
In [11]: s='\x41'
In [12]: s
Out[12]: 'A'

In [13]: s='\xc4'
In [14]: s
Out[14]: 'Ä'

3. unicode short
\u()()()() 형태로 \u 다음 4자리

In [15]: s='\u00c4'
In [16]: s
Out[16]: 'Ä'

4. unicode long
\U()()()()()()()() 형태로 \U 다음 8자리

In [17]: s='\U000000c4'
In [18]: s
Out[18]: 'Ä'
#

'Python > string' 카테고리의 다른 글

append, pop, sort, reverse  (0) 2019.12.27
encode, decode  (0) 2019.12.26
string format  (0) 2019.12.26
strip, rstrip, lstrip  (0) 2019.12.26
isalpha  (0) 2019.12.26

2 methods

1. % method
2. format() method

example)
In [7]: '%s, A, %s, and B' % ('first', 'second')
Out[7]: 'first, A, second, and B'

In [8]: '{}, A, {}, and B'.format('first', 'second')
Out[8]: 'first, A, second, and B'

In [20]: '{:>30,.2f}'.format(296999.2567)
Out[20]: ' 296,999.26'

In [21]: '{:>30,.2f}'.format(296999.2567)
Out[21]: ' 296,999.26'

In [22]: '{:>20,.2f}'.format(296999.2567)
Out[22]: ' 296,999.26'

In [23]: '{:->20,.2f}'.format(296999.2567)
Out[23]: '----------296,999.26'

In [24]: '{:_>20,.2f}'.format(296999.2567)
Out[24]: '__________296,999.26'
#

'Python > string' 카테고리의 다른 글

encode, decode  (0) 2019.12.26
ascii, hex, unicode  (0) 2019.12.26
strip, rstrip, lstrip  (0) 2019.12.26
isalpha  (0) 2019.12.26
upper()  (0) 2019.12.26

명령어 string method

strip, rstrip, lstrip

사용법

결과

차례로 문자열의 양쪽, 오른쪽, 왼쪽 공백문자를 없애준다

예시

In [1]: a=' 111 '

In [2]: a

Out[2]: ' 111 '

In [3]: a.rstrip()

Out[3]: ' 111'

In [4]: a.lstrip()

Out[4]: '111 '

In [5]: a.strip()

Out[5]: '111'

'Python > string' 카테고리의 다른 글

ascii, hex, unicode  (0) 2019.12.26
string format  (0) 2019.12.26
isalpha  (0) 2019.12.26
upper()  (0) 2019.12.26
split  (0) 2019.12.26

+ Recent posts