The char.swapcase()
function in NumPy returns a copy of a string or array, depending on the input whose uppercase characters are converted to lowercase and vice versa, element-wise. In simpler words, all the uppercase elements are converted to lowercase, while all the lowercase elements are converted to uppercase.
char.swapcase(a)
The char.swapcase()
function takes a single and mandatory parameter value, a
, which represents the input array or the string.
The char.swapcase()
function returns an output array of strings or Unicodes, depending on the input type that is passed to the function.
import numpy as np# creating an arraymyarray = np.array(["THAT", "There", "ThESE", "they"])# implementing the char.swapcase() functionprint(np.char.swapcase(myarray))
We converted all the uppercase characters of each element of the input array called myarray
to lowercase characters and vice versa, using the char.swapcase()
function.