TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python String | expandtabs() method with Examples

Python String expandtabs() method with Examples on capitalize(), center(), count(), encode(), find(), format(), index(), join(), lower(), ljust(), isupper(), istitle(), isspace(), isprintable(), isnumeric(), islower() etc.

<< Back to PYTHON

Python String expandtabs() Method

Python expandstabs() method replaces all the characters by sepecified spaces. By default a single tab expands to 8 spaces which can be overridden according to the requirement.

We can pass 1, 2, 4 and more to the method which will replace tab by the these number of space characters.

Signature

expandtabs(tabsize=8)

Parameters

tabsize : It is optional and default value is 8.

Return Type

It returns a modified string.

Let's see some examples to understand the expandtabs() method.

Python String expandtabs() Method Example 1

Calling method without specifying spaces. It sets to it's default value.

# Python endswith() function example
# Variable declaration
str = "Welcome \t to \t the \t TheDeveloperBlog."
# Calling function
str2 = str.expandtabs()
# Displaying result
print(str2)

Output:

Welcome          to      the     TheDeveloperBlog.

Python String expandtabs() Method Example 2

See, how the output is changing after each call. Each method is set to different-different number of spaces.

# Python endswith() function example
# Variable declaration
str = "Welcome \t to \t the \t TheDeveloperBlog."
# Calling function
str2 = str.expandtabs(1)
str3 = str.expandtabs(2)
str4 = str.expandtabs(4)
# Displaying result
print(str2)
print(str3)
print(str4)

Output:

Welcome   to   the   TheDeveloperBlog.
Welcome    to    the   TheDeveloperBlog.
Welcome      to      the     TheDeveloperBlog.

Next TopicPython Strings




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf