Python String expandtabs() Method


Contents

Description

The expandtabs() method in Python String returns a copy of the string where the tab characters ie. '\t' use spaces to expand, making use of the given tabsize (default 8) optionally.

Syntax

str.expandtabs(tabsize=8)

Parameters

  • tabsize − It specifies the number of characters which are to be replaced for a tab character '\t'.
  • Return Value
  • This method returns a copy of the string where tab characters i.e., '\t' has been expanded making use of the spaces.

Example

#!/usr/bin/python

str = "this is\tstring example....wow!!!";

print "Original string: " + str
print "Defualt exapanded tab: " +  str.expandtabs()
print "Double exapanded tab: " +  str.expandtabs(16)

Result

Original string: this is        string example....wow!!!
Defualt exapanded tab: this is string example....wow!!!
Double exapanded tab: this is         string example....wow!!!

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial