The char.expandtabs()
function in Python is used to return a copy of each string element of an array in such a way that all the tab characters are replaced by one or more spaces.
char.expandtabs(a, tabsize=8)
a
: This represents the input array.tabsize
: This is used to replace the tabs. The default value is 8 spaces. This is optional.This function returns an output array of strings or Unicode, depending on the input.
# A code to illustrate the char.expnadtabs() function# importing the numpy libraryimport numpy as np# implementing the char.expandtabs() functionnew_array = np.char.expandtabs(["Theo\thow\tare\tyou\ttoday?"], 16)# printing the expanded tabsprint(new_array)
numpy
module.16
by using the char.expandtabs()
function. We'll assign the result to a variable, my_array
.my_array
.