Python Forum
Tab character in a string prints 8 spaces
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tab character in a string prints 8 spaces
#1
Hi,

I'm starting an online Python class and have been using Python 3 latest with IDLE. I open Python first then open IDLE next to it. Well, I got to the section using the newline and tab characters when printing strings. Then noticed something peculiar on the output. IDLE is configured to treat tabs as 4 spaces, but when the print command runs a string with the \t in it, it shows 8 spaces on the output.

print("Line 1\n\tLine 2")
Output comes out like this:
Output:
Line 1 Line 2
Instead of this:
Output:
Line 1 Line 2
The first thing I did was check IDLE's tab stop configuration and it was already set to 4 spaces. I changed it to 2 spaces but the output still shows 8 spaces.

Thank you for helping in demystifying this issue.
Reply


Messages In This Thread
Tab character in a string prints 8 spaces - by hecresper - Aug-26-2019, 10:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split string into 160-character chunks while adding text to each part iambobbiekings 9 9,852 Jan-27-2021, 08:15 AM
Last Post: iambobbiekings
  Help with removing spaces and tabs from a string msqpython 14 4,312 Jan-21-2021, 10:48 PM
Last Post: deanhystad
  Replacing a few characters of a specified character but not all of them from a string fatherted99 7 3,448 Aug-13-2020, 09:08 AM
Last Post: fatherted99
  not find the resone it not prints yukhei 3 1,844 May-22-2020, 03:36 PM
Last Post: deanhystad
  Finding and storing all string with character A at middle position Pippi 2 2,773 Jan-20-2019, 08:23 AM
Last Post: Pippi
  Unexpected character after line continuation character joshyb123 5 10,818 Sep-05-2018, 08:08 AM
Last Post: perfringo
  unexpected character after line continuation character error newbie 10 14,954 Aug-09-2018, 06:07 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020