Python string expandtabs function

Replace tabs with spaces

Python can replace tabs in a string by space characters with a simple method called expandtabs. expandtabs has the following syntax.

s.expandtabs([tabsize]) Replaces tabs in string s with tabsize spaces (default is 8).


s = "\tjava2s.com\t"
t = s.expandtabs()
print t

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary