For programmers, in fact, tabs and spaces are far more than just a question of "position".
The length of the tab may be inconsistent in different editors, so after setting indentation with tab in one editor, the indentation may be messed up in other editors. This problem does not occur with spaces, because spaces occupy one character position.
As we all know, Tab in ASCII code, the code is 9, and the space is 32. This means that when we press a Tab, even if it looks like 8 spaces (or 4 spaces, in different environments, Tab may display different effects), it is completely different to the computer. The same thing. This also means that for codes that use characters to describe the process, it is most likely to be a decisive difference.
Especially for a language that uses space indentation to distinguish code levels-Python.
Let's look at a piece of code.
classMyForm(Form):
value1 =StringField('value1')
value2 =StringField('value2')
value3 =StringField('value3') #This line uses Tab indentation
submit =SubmitField('Submit')
learn python ='QQ group:725479218'
It seems that this value3 variable is no different from other variables, but there is such an error-indentation error.
value3 =StringField('value3')
IndentationError: unexpected indent
In fact, Python does not force you to use Tab indentation or space indentation, and even the number of spaces is not mandatory, but it is absolutely! Tabs and spaces must not be mixed, so here, is there a big difference between spaces and tabs?
At this time, some children's shoes are about to be mentioned. Why have I never had such a problem with PyCharm (or other IDE)?
In fact, many IDEs have made various optimizations for the Tab key. One of them is to expand the Tab key to a space. That is to say, when you press Tab, the IDE actually helps you put a "9 "Is converted into four (or eight) "32". But be aware that not all IDEs do this kind of work for you! In the same way, for the editor Vim, which is so pure and unpretentious, it will definitely not help you do this kind of work.
Since Tab displays differently in different environments, the spaces are always the same. For some detailed typesetting and indentation (for example, if you want to align each line of comments), using spaces is more precise. It seems that using spaces to write code is better than using Tab.
**The benefits of spaces instead of Tab: **
The code is what you want in all cases. The tab only looks good when you and the code author's tab size is set to the same. Modifying the tab size does not solve this problem, because it is difficult for you to modify the tab size every time you open a file, and everyone usually has different habits (the POSIX/Unix standard tab should be 8 characters wide, Linus also stipulated The tab size of all codes in the Linux kernel is 8). If there are end-of-line comments, the tab size must be set to be the same as the author, which means that you need to modify the tab size frequently when you look at different codes. I have seen many codes, and the tab sizes used are from 2, 3, 4, 5, 6, 8, 16 or even 32. If you use a tab size different from the author, the appearance will be very undesirable.
Reliable IDEs can solve the problem of increasing and reducing indents in forward and backward directions. Even if it is four spaces, a backspace key can also retreat, so there is no problem in the convenience of use. ——If you complain that deleting adjustments cannot be effectively resolved, you need to study your editor. In fact, there are shortcut keys for increasing or decreasing indentation directly in mainstream editors. No matter it is tab or space or backspace, it is rarely used directly for indentation.
tab is a tab character rather than an indentation character, as it is used extensively in html pages <table 进行布局是个不好的编程习惯一样,在编程中大量使用制表符布局通常也不是个好习惯。
Under normal circumstances, team development must formulate a set of coding standards. In most teams, using 4 spaces instead of Tab is the default. Therefore, it is highly recommended that you use spaces instead of Tab. In addition, each IDE (editor) provides the function of automatically converting spaces into tabs. As long as you set it up, you can press the tab key to display 4 or more spaces.
Content expansion:
Use of Python_Tab key
In[1]: an_orange =27
In[2]: an_pear =15
In[3]:an(press<Tab )
anorange an_pear and any
In[1]: a =[1,2,3]
In[2]: a.<Tab
a.append a.extend a.remove a.sort
a.count a.index a.pop a.reserve
In[1]:import pandas
In[2]: pandas.<Tab
pandas.cut pandas.core pandas.concat
When entering anything that looks like a file path (even in a Python string), press the Tab key to find out what matches it in the computer's file system.
The Tab key auto-completion function can be used for function keyword parameters.
So far, this article on what the tab key in python means is introduced here. For more related content on what the tab key in python means, please search for the previous articles of ZaLou.Cn or continue to browse the related articles below. Hope you all Support ZaLou.Cn a lot!
Recommended Posts