HackerRank/ハッカーランキング-sWAP cASE-python


質問する



に答える

  • 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.
  • 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.
  • コード#コード#

    # HackerRank, sWAP cASE, python3
    def swap_case(s):
        result = [x.lower() if x.isupper() else x.upper() for x in s]
        return ''.join(result)
    
    if __name__ == '__main__':
        word = str(input())
        
        print(swap_case(word))

    結果



    ソース&ハーブ


    HackerRank
    github