Hey everyone! I'm just starting my Python journey and I'm working through Mike McGrath's "Coding for Beginners". I know I'm a total newbie, but I'm aiming to get my fundamentals right from the start. One thing that's throwing me off is the spacing when I run my code. The examples in the book often look different from what I see in my IDLE window, especially when it comes to tabs and spaces. I've noticed that sometimes the formatted output doesn't line up like it's supposed to, particularly when using tab characters. The book is a couple of years old, and I'm using a newer version of Python, which might be part of the problem. Can anyone explain why this is happening? What's the best practice for using spaces and tabs in Python so I can avoid developing bad habits? Here's an example of what I'm working with:
a=8
b=4
print('Assign Values:t' , 'a=' , a , 'tb=' , b)
a+=b
print('Assign Values:t' , 'a=' , a , 't(8+=4)')
a-=b
print('Subtract & Assign:t' , 'a=' , a , 't(12-4)')
a*=b
print('Multiply & Assign:t' , 'a=' , a , 't(8x4)')
a/=b
print('Divide & Assign:t' , 'a=' , a , 't(32/4)')
a%=b
print('Modulus & Assign:t' , 'a=' , a , 't(8%4)')
3 Answers
Don't worry too much about the precise spacing when using print statements! Python ignores extra spaces outside of quotes, but they do matter inside them. As for your issue with alignment, it might be worth checking how your terminal handles output size. If things look off, it could be due to narrow terminal width overwriting some parts. Check your terminal settings or try running your code in a different IDE to see if it looks better there!
Congrats on your coding journey! The weird output is probably due to how tab characters ( ) are rendered differently on various systems. Most terminals set tab stops to 8 spaces, but some might display them differently based on your settings. Stick with the main style of printing, like using print('Assign Values:t', 'a=', a, 'tb=', b). Also, to keep things uniform, you might consider using f-strings for formatting your prints. They provide a lot more control over spacing than just using commas!
Hey there! It sounds like you're worried about how your output looks compared to the examples. Just so you know, the discrepancies can often come from various factors like the terminal settings or the font you're using. Don't stress too much about it — what's important is that your code runs properly. Regarding using the spacebar, as a rule of thumb, add spaces after commas and around operators for better readability. If you're looking for the "right" way to format your code, definitely check out PEP 8, the style guide for Python. It’ll help you get a better grip on spacing and formatting.

I've definitely run into that terminal width issue before. It's a simple fix though — try resizing your window a bit, or you could run it in a different environment like Jupyter or an online compiler to see if that makes a difference!