1. 소문자를 대문자로 바꾸어보자 : upper( )¶
소문자를 대문자로 바꾸는 함수는 upper()로 아래와 같이 사용한다.
In [1]:
food = 'chocolate'
In [2]:
food.upper()
Out[2]:
'CHOCOLATE'
대문자를 소문자로 바꾸어보자 : lower( )¶
대문자를 소문자로 바꾸는 함수는 lower()로 아래와 같이 사용한다.
In [4]:
book = 'PYTHON'
In [5]:
book.lower()
Out[5]:
'python'
여기서 우리는 등호(=)를 통해 변수를 메모리에 저장하지 않았으므로 변수는 바뀌지 않았음을 잊지말자
In [6]:
book
Out[6]:
'PYTHON'
긴 문장도 당연히 가능하다.
In [7]:
sentence = '''Patience conquers the world. Patience is the key to paradise. Patience devours the devil. Will is power. Seize the day. Slow and steady win the game. No bees, no honey. If there is no wind, row.'''
In [8]:
sentence.upper()
Out[8]:
'PATIENCE CONQUERS THE WORLD. PATIENCE IS THE KEY TO PARADISE. PATIENCE DEVOURS THE DEVIL. WILL IS POWER. SEIZE THE DAY. SLOW AND STEADY WIN THE GAME. NO BEES, NO HONEY. IF THERE IS NO WIND, ROW.'
In [9]:
sentence.lower()
Out[9]:
'patience conquers the world. patience is the key to paradise. patience devours the devil. will is power. seize the day. slow and steady win the game. no bees, no honey. if there is no wind, row.'
'파이썬 기초문법' 카테고리의 다른 글
[파이썬 기초] 문자열 추출 : [대괄호]를 이용한 데이터 억세스와 슬라이싱([:]) (0) | 2022.03.16 |
---|---|
[파이썬 기초] 문자열을 분리해보자 split() (0) | 2022.03.16 |
[파이썬 기초] 파이썬 문자열 만들기, 여러 줄의 글을 문자열로! Python Strings (0) | 2021.11.18 |
[파이썬 기초] 데이터 타입을 확인하고 변환시켜보자, type(), int(), str(),float() (0) | 2021.11.15 |
[파이썬 기초] 하나만 바꿔서 출력할 수 는 없나? 문자열 formating (0) | 2021.11.14 |