Wednesday, January 9, 2019

Python -SwapCase



In python , we have a functionality by which we can swap the cases from upper to lower and vice versa. This can be achieved by the function called swapcase .

Example :- The input that will be provided here will get converted into
the alternative case

data = input()

print(data.swapcase())

We can convert the case with writing a function also.

Example :-
def swap_case(s):
result1=""
for i in s:
if i.isupper():
newletter= i.lower()
result1 += ''.join(newletter)
else:
newletter=i.upper()
result1 +=''.join(newletter)
return result1

if __name__ == '__main__':
s = input()
result = swap_case(s)
print(result)

No comments:

Post a Comment

Hadoop - What is a Job in Hadoop ?

In the field of computer science , a job just means a piece of program and the same rule applies to the Hadoop ecosystem as wel...