Question: the swapcase method for strings takes lowercase letters and capitlizes them, and then takes uppercase letters and makes them lowercase. Without using the swapcase method,

the swapcase method for strings takes lowercase letters and capitlizes them, and then takes uppercase letters and makes them lowercase. Without using the swapcase method, build your own using a function and taking in a string In [1]: string = "I like to code in Python!" print("original string:",string) swapped_string = string.swapcase) print (swapped_string) original string: I like to code in Python! i LIKE TO CODE IN PYTHON ! In [7]: from string import ascii_lowercase as lowercase from string import ascii_uppercase as uppercase print(lowercase) print(uppercase) abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ In [39]: def swapcase_function(string): output=[] for i in string: if i in range (ord("a"), ord("z")): i = ord(i) -32 output = chr(i) elif i in range (ord("A"), ord("Z")): i = ord(i)+32 output = chr(i) print (output) return output In [40]: swapcase_function("HELLO") [] Out[40]: []
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
