Engineering Note

[Python] startswith 함수 본문

Programming Language/Python

[Python] startswith 함수

Software Engineer Kim 2021. 8. 31. 16:28

startswith

  • 파이썬의 문자열의 첫 글자 확인을 도와주는 함수이다.

startwith 사용방법

  • 문자열.startwith('특정 문자열')
# 트럼프 대통령 트윗을 공백 기준으로 분리한 리스트입니다. 수정하지 마세요.
trump_tweets = ['thank', 'you', 'to', 'president', 'moon', 'of', 'south', 'korea',
'for', 'the', 'beautiful', 'welcoming', 'ceremony', 'it', 'will', 'always', 'be', 'remembered']

def print\_korea(tweet):  
# 문자열로 구성된 리스트에서 k로 시작하는 문자열을 출력합니다.  

for word in tweet:  
    if word.startswith('k'):  
    print(word)

# 아래 주석을 해제하고 결과를 확인해보세요.

print_korea(trump_tweets)
Comments