본문 바로가기
파이썬

파이썬에서 문자가 대문자인지 확인하는 방법은 무엇입니까?

by º기록 2020. 11. 4.
반응형

나는 이와 같은 문자열이

>>> x="Alpha_beta_Gamma"
>>> words = [y for y in x.split('_')]
>>> words
['Alpha', 'beta', 'Gamma']

목록 단어의 두 번째 요소가 소문자로 시작하고 x = "Alpha_Beta_Gamma" 문자열이 일치하는 경우 X가 일치하지 않는다는 출력을 원합니다.

 

해결 방법

 


>>> help(str.istitle)
Help on method_descriptor:

istitle(...)
    S.istitle() -> bool

    Return True if S is a titlecased string and there is at least one
    character in S, i.e. uppercase characters may only follow uncased
    characters and lowercase characters only cased ones. Return False
    otherwise.

>>> "Alpha_beta_Gamma".istitle()
False
>>> "Alpha_Beta_Gamma".istitle()
True
>>> "Alpha_Beta_GAmma".istitle()
False

 

참조 페이지 https://stackoverflow.com/questions/3668964

 

 

반응형

댓글