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

Publicado el: 08 septiembre 2021
en el canal de: Bhanu Prathap
1,826
10

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
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
HackerRank.com presents "Pythonist 2".

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

Solution:
def swap_case(s):
output=''
for character in s:
if character.isupper():
output=output+character.lower()
elif character.islower():
output=output+character.upper()
else:
output=output+character
return output

One line solution:
def swap_case(s):
return s.swapcase()


En esta página del sitio puede ver el video en línea HackerRank Python Problem No8 || String || Swap the case de Duración hora minuto segunda en buena calidad , que subió el usuario Bhanu Prathap 08 septiembre 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,826 veces y le gustó 10 a los espectadores. Disfruta viendo!