여태 필요하면 구글에 검색해서 사용하다가 파이썬 공식 문서를 보면서 정리해봤다. 역시 공식 홈페이지에는 뭐가 많다.
String constants (문자열 상수)
string.ascii_letters : 소문자 a ~ z + 대문자 A ~ Z
string.ascii_lowercase : 소문자 a ~ z
string.ascii_uppercase : 대문자 A ~ Z
string.digits : 숫자 0 ~ 9
string.hexdigits : 16진법, 0 ~ 9 + a ~ f + A ~ F
string.octdigits : 8진법, 0~7
string.punctuation : 특수문자
string.printable : 숫자 + 대소문자 + 특수문자 + 공백
string.whitespace : 공백
# 알고리즘 문제에서 자주 쓰이는 문자열 상수
letters = string.ascii_letters
# 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
lowercase = string.ascii_lowercase
# 'abcdefghijklmnopqrstuvwxyz'
uppercase = string.ascii_uppercase
# 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = string.digits
# '0123456789'
punctuation = string.punctuation
# '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
# 알아두기
hexdigits = string.hexdigits
# '0123456789abcdefABCDEF'
octdigits = string.octdigits
# '01234567'
printable = string.printable
# '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
whitespace = string.whitespace
# ' \t\n\r\x0b\x0c'
# whitespace 차이
print('characters space : ab cd')
print('tab : ab\tcd')
print('linefeed : ab\ncd')
print('--------')
print('return : ab\rcd')
print('--------')
print('formfeed : ab\vcd')
print('formfeed2 : ab\x0bcd')
print('vertical tab : ab\fcd')
print('vertical tab2 : ab\x0ccd')
characters space : ab cd
tab : ab cd
linefeed : ab
cd
--------
cd
--------
formfeed : abcd
formfeed2 : abcd
vertical tab : abcd
vertical tab2 : abcd
GitHub - python/cpython: The Python programming language
The Python programming language. Contribute to python/cpython development by creating an account on GitHub.
github.com
https://docs.python.org : string constants
string — Common string operations
Source code: Lib/string.py String constants: The constants defined in this module are: Custom String Formatting: The built-in string class provides the ability to do complex variable substitutions ...
docs.python.org
항상 알고나면 간단해지는 것 같다.
'Input > python' 카테고리의 다른 글
파이썬 문자열의 글자 구성 파악 is__() : islower(), isupper(), isdigit(), isalpha() (0) | 2023.11.04 |
---|---|
파이썬 에러 정리 : SyntaxError, TypeError, ValueError, IndexError (0) | 2023.10.31 |
[python] 파이썬 공식홈페이지 set : 생성, 원소 추가 & 삭제 (0) | 2023.05.11 |
[python] 파이썬 공식홈페이지 set : 교집합, 합집합, 차집합, 포함 관계, 서로소 (0) | 2023.05.11 |
[python] 파이썬 공식홈페이지 dictionary view objects : dict.keys() / dict.values() / dict.items() (0) | 2023.04.18 |