티스토리 뷰

728x90

sWAP cASE

You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.

For Example:

Www.HackerRank.com → wWW.hACKERrANK.COM
Pythonist 2 → pYTHONIST 2  

Function Description

Complete the swap_case function in the editor below.

swap_case has the following parameters:

  • string s: the string to modify

Returns

  • string: the modified string

Input Format

A single line containing a string s.

Constraints

Sample Input 0

HackerRank.com presents "Pythonist 2".

Sample Output 0

hACKERrANK.COM PRESENTS "pYTHONIST 2".

 

문제해석

입력되는 string에서 대문자는 소문자로 소문자는 대문자로 각각 변경하여 출력하면 된다.

 

문제풀이

보통 lower(), upper() 이렇게 제공하는데, 파이썬에서는 친절하게도 swapcase()라는 함수를 제공한다.

def swap_case(s):
    return s.swapcase()

if __name__ == '__main__':
    s = raw_input()
    result = swap_case(s)
    print result
728x90
LIST
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함