(Aug-27-2019, 01:46 PM)metulburr Wrote: If the PEP8 defines the default should be 4 spaces, why is it defaulted to 8 spaces there? I mean its testing anyways, but it does confuse new people as to why they are sometimes getting 8 spaces when they are told they should be getting 4.It's not Python specific it's just how tabs work Tab key.
They could have changed to 4 to avoid confusion between code indentation(always use 4-space) and output of
\t
8-space. Quote:the horizontal tab size of 8 evolved because as a power of two it was easier to calculate with the limited digital electronics available
When think of of it i never use
\t
,it always string formatting when i need to move or get a different output.Also
\t
can be tricky,it start count at 3 then pushes it up to 8 ![Confused Confused](https://python-forum.io/images/smilies/confused.png)
>>> print('aaa\taaaaaa\taaa') aaa aaaaaa aaaA usage i showed in a resent Thread,of course
f-string
as now always use. my_string = ("go") my_list = [1, 2, 3, 4] for item in my_list: print(f'|{my_string} -->{item:4}|')
Output:|go --> 1|
|go --> 2|
|go --> 3|
|go --> 4|
item:30
Output:|go --> 1|
|go --> 2|
|go --> 3|
|go --> 4|
Can also solve first task,but not so common usage this and maybe a case when expandtabs(4)
can make sense.Never used
expandtabs(4)
as if need a other output with string it's always sting formatting(f-string
). >>> print(f"Line 1\n{'Line 2':>10}\n{'Line 3':>14}") Line 1 Line 2 Line 3