HackerRank Python Problem No8 || String || Swap the case

preview_player
Показать описание
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:

Pythonist 2 → pYTHONIST 2

Function Description
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 .

Sample Input 0

Sample Output 0
hACKERrANK.COM PRESENTS "pYTHONIST 2".

Solution:
def swap_case(s):
output=''
for character in s:
else:
output=output+character
return output

One line solution:
def swap_case(s):
Рекомендации по теме
visit shbcf.ru