2016-10-26 5 views
-1

파이썬에서 문자열 안에 각 하위 문자열을 추출하는 방법이 있습니까?문자열에서 하위 문자열 가져 오기?

예를 들어

내가 문자열

"Hello there my name is Python" 

내가 "Hello", "there" , "my" , "name" , "is" 각이 문자열에서 촬영 "Python"을 가질 수 있도록이 캐릭터 라인 내에서 각 하위 문자열 (또는 개별 단어)를 꺼내하려는에게이 있다면?

+2

적어도 검색해야합니다. 'str.split'은 여러분이 원하는 것입니다. –

+0

'a = "안녕하세요, 제 이름은 파이썬입니다."그리고 나서'b = a.split()' – roganjosh

+0

https://docs.python.org/2/library/stdtypes입니다. html # str.split – wim

답변

0

나는 당신이 찾고있는 것이 split 방법이라고 믿습니다.

문자열을 지정된 구분 기호로 분리합니다. 기본 delimeter는 공백입니다.

input_string = "Hello there my name is Python" 
for substring in input_string.split(): 
    print(substring) 
0

split() 문자열 방법을 사용하십시오.

>>> sentence = 'Hello there my name is Python' 
>>> words = sentence.split() 
>>> print words 
['Hello', 'there', 'my', 'name', 'is', 'Python'] 
관련 문제