ブリブリ備忘録 おっ、python

HackerRankの問題とコメント(python3) 拙いですが...

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

Input Format

A single line containing a string .

Constraints

 

Output Format

Print the modified string .

Sample Input 0

HackerRank.com presents "Pythonist 2".

Sample Output 0

hACKERrANK.COM PRESENTS "pYTHONIST 2".

ソースコード

def swap_case(s):
    swap=s.swapcase()
    return swap
if __name__ == '__main__':
    s = input()
    result = swap_case(s)
    print(result)

・コメント

標準入力で与えられた文字列の大文字小文字を入れ替えるだけの問題。

入れ替えるときに用いる関数(swapcase()なるもの)が用意されているのでそれにぶち込めば終わり。

あまり使い所もなさそう(知らんけど...)

・URL

https://www.hackerrank.com/challenges/swap-case/problem