Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
How to Print a Dictionary in Python
Next article icon

How to Print a Tab in Python

Last Updated : 26 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, printing a tab space is useful when we need to format text, making it more readable or aligned. For example, when displaying data in columns, we might want to add a tab space between the values for a cleaner appearance. We can do this using simple methods like \t, the print() function or by using the str.format() method.

Using the Special Character \t

The easiest and most common way to print a tab space is by using the special character \t. This represents a tab space in Python.

Python
# Using \t to print a tab a = "Hey" b = "Geek" print(a , "\t" , b) 

Output
('Hey', '\t', 'Geek') 

Table of Content

  • Print a Tab in Python Using 'sep' Parameter
  • Using the Special Character \t
  • Using str.format()

Print Tab in Python Using 'sep' Parameter

The print() function in Python accepts a 'sep' parameter in which specifies the separator between the multiple values passed to the function. By default 'sep' is set to the ' ' (space) but we can change it to '\t' to the insert tabs between the values.

Python
# Using sep in print to insert a tab a = "Hello" b = "Geek" print(a, b, sep="\t") 

Output
Hello	Geek 

Using String Concatenation

We can also print a tab by string concatenation that contains \t with other strings.

Python
# Using \t directly in print a = "Geek" b = "Rocks" print(a + "\t" + b) 

Output
Geek	Rocks 

Using str.format()

If we want more control over formatting, we can use str.format() to insert a tab between values.

Python
# Using str.format() for tab space a = "Geeky" b = "Fun" print("{}\t{}".format(a, b)) 

Output
Geeky	Fun 

Next Article
How to Print a Dictionary in Python

S

subramanyasmgm
Improve
Article Tags :
  • Python
  • Python Programs
  • python-string
Practice Tags :
  • python

Similar Reads

  • How to Print a Dictionary in Python
    Python Dictionaries are the form of data structures that allow us to store and retrieve the key-value pairs properly. While working with dictionaries, it is important to print the contents of the dictionary for analysis or debugging. Example: Using print Function [GFGTABS] Python # input dictionary
    3 min read
  • How to Print without newline in Python?
    In Python, the print() function adds a newline by default after each output. To print without a newline, you can use the end parameter in the print() function and set it to an empty string or a space, depending on your needs. This allows you to print on the same line. Example: [GFGTABS] Python print
    3 min read
  • How to Print Dictionary Keys in Python
    We are given a dictionary and our task is to print its keys, this can be helpful when we want to access or display only the key part of each key-value pair. For example, if we have a dictionary like this: {'gfg': 1, 'is': 2, 'best': 3} then the output will be ['gfg', 'is', 'best']. Below, are the me
    2 min read
  • How to Print a List Without Brackets in Python
    In this article, we will see how we can print a list without brackets in Python. Whether we're formatting data for user interfaces, generating reports, or simply aiming for cleaner console output, there are several effective methods to print lists without brackets. Using * Operator for Unpacking Lis
    2 min read
  • How to copy a string in Python
    Creating a copy of a string is useful when we need a duplicate of a string to work with while keeping the original string intact, strings in Python are immutable which means they can't be altered after creation, so creating a copy sometimes becomes a necessity for specific use cases. Using SlicingSl
    2 min read
  • Print the Content of a Txt File in Python
    Python provides a straightforward way to read and print the contents of a .txt file. Whether you are a beginner or an experienced developer, understanding how to work with file operations in Python is essential. In this article, we will explore some simple code examples to help you print the content
    3 min read
  • How to clear screen in python?
    When working in the Python interactive shell or terminal (not a console), the screen can quickly become cluttered with output. To keep things organized, you might want to clear the screen. In an interactive shell/terminal, we can simply use ctrl+l But, if we want to clear the screen while running a
    5 min read
  • How to Repeat a String in Python?
    Repeating a string is a simple task in Python. We can create multiple copies of a string by using built-in features. This is useful when we need to repeat a word, phrase, or any other string a specific number of times. Using Multiplication Operator (*):Using Multiplication operator (*) is the simple
    2 min read
  • Print Alphabets till N-Python
    Printing Alphabets till N in Python involves generating a sequence of uppercase or lowercase letters starting from 'A' (or 'a') up to the N-th letter of the alphabet. For example, if N = 5, the output should be: 'A B C D E'. Let's explore a few ways to implement this in a clean and Pythonic way. Usi
    2 min read
  • How to Append to String in Python ?
    In Python, Strings are immutable datatypes. So, appending to a string is nothing but string concatenation which means adding a string at the end of another string. Let us explore how we can append to a String with a simple example in Python. [GFGTABS] Python s = "Geeks" + "ForGeeks
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences