개발공부

[Python]String +연산자, upper(), lower(), title(), spit() 본문

Python/Basic

[Python]String +연산자, upper(), lower(), title(), spit()

mscha 2022. 4. 20. 17:23

+연산자

  - 숫자 뿐만 아니라 문자열에서도 사용이 가능하다.

  - 여러 문자열들을 결합할 수 있다.

>>> first_name = 'Mitch'
>>> last_name = 'Steve'
>>> first_name + last_name
'MitchSteve'

upper()

  - 문자열을 대문자로 변경한다.

>>> full_name = 'Mitch Steve'
>>> full_name.upper()
'MITCH STEVE'

 

lower()

  - 문자열을 소문자로 변경한다.

>>> full_name = 'Mitch Steve'
>>> full_name.lower()
'mitch steve'

 

title()

 - 문자열 안의 단어들의 첫 문자를 대문자로 변경한다.

>>> full_name = 'mitch steve'
>>> full_name.title()
'Mitch Steve'

split()

 - 문자열을 원하는 기준으로, 각각 분리한다. (분리되어 만들어진 것은 리스트 형태)

>>> full_name = 'Mitch Steve'
>>> full_name.split()
['Mitch', 'Steve']

>>> full_name.split('t')
['Mi', 'ch S', 'eve']

'Python > Basic' 카테고리의 다른 글

[Python] String len(), find(), rfind()  (0) 2022.04.20
[Python] String 변경, replace()  (0) 2022.04.20
[Python] String 특징, 생성, Slicing(슬라이싱)  (0) 2022.04.20
[Python]Boolean  (0) 2022.04.20
[Python] print(), input(), 형변환  (0) 2022.04.18