How to print a Tab in Python : 3 Methods

The tab is a default space. There are many ways to print the tab in Python. In this post, you will some of the best ways to print a Tab in Python.

Methods to print a Tab in Python

Let’s explore all the methods to print a Tab in Python

Method 1: Use the \t character in the string

The first method to print the tab in Python is the use of\t character in the string. Below is an example of it.

website_name = 'Code\tThe\Best'
print(website_name )

Method 2: Use a tab when formatting a string

You can also use the tab while formatting a string literal. As you already know that formatting a string using the “f ” that allows you to use any variable inside the string. In this method, you will first define a variable that will contain the tab literal (\t) and use this variable inside the string.

tab = '\t'

string = f'code{tab}the{tab}best'

Method 3: Using the tab with str.format()

In the second method, you have to use the “f” for formatting the string. Here you will use the str.format() function to include the tab variable inside the string.

Use the below lines of code to format the string with the tab literal.

string1 = "Code"
string2 = "The"
string 3= "Best
string = '{}\t{}\t{}'.format(string1,string2,string3)


The above are the methods to print the tab to the screen. You can use any method of your choice. The best method I will suggest is method 3 which uses the formatting of the string.

Hi, I am CodeTheBest. Here you will learn the best coding tutorials on the latest technologies like a flutter, react js, python, Julia, and many more in a single place.


This Offer is Limited! Grab your Discount!
15000 ChatGPT Prompts
Offer Expires In: