+ Development/Python
[Python] 대문자 / 소문자 변환 및 Check 하기
:: Teacher ::
2020. 2. 4. 19:27
728x90
반응형
개발하다보면, 대문자 / 소문자중 한가지로 표현이 필요한 경우가 있다.
이때 아래와 같은 함수를 통해서 변환 및 Check 해보도록 하자.
1. 대문자 변환 - upper() 함수
Python 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = 'abcd' >>> print a.upper() ABCD >>> >>> b = 'aBcD' >>> print b.upper() ABCD
2. 소문자 변환 - lower() 함수
Python 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = 'ABCD' >>> print a.lower() abcd >>> >>> b = 'aBcD' >>> print b.lower() abcd
3. 대문자 / 소문자 Check - isupper() 함수, islower() 함수
Python 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = 'ABCD' >>> b = 'abcd' >>> c = 'aBCd' >>> >>> print a.isupper() True >>> print a.islower() False >>> >>> print b.isupper() False >>> print b.islower() True >>> >>> print c.isupper() False >>> print c.islower() False
위에 작성한 예제만 보면 큰 어려움없이 변환 혹은 Check를 할 수 있으니 유용하게 사용하도록 하자.
728x90
반응형