문자열 대소문자 함수

야금야금 공부·2023년 3월 27일

파이썬 정리

목록 보기
4/5

1. 모든 문자를 대문자로 바꿀 때 : upper()

test = "hello World"
print(test.upper())   # HELLO WORLD

2. 모든 문자를 소문자로 바꿀 때 : lower()

test = "Hello WoRLD"
print(test.lower())   # hello world

3. 문자열의 첫 글자는 대문자로, 나머지 문자열은 모두 소문자로 변환 : capitalize()

test1 = "hello world"
test2 = "Hello WORLD"

print(test1.capitalize())   # Hello world
print(test2.capitalize())   # Hello world

4. 모든 단어의 첫글자를 대문자로 : title()

test = "welcome to python"
print(test.title())     # Welcom To Python

5. 대문자 ↔ 소문자 : swapcase()

test = "Welcome To Python"
print(test.swapcase())     # wELCOME tO pYTHON

0개의 댓글