Home > Article > Backend Development > What is Python tab character
Through previous studies, I believe everyone has a preliminary understanding of Python. Today I will introduce to you the Python tab character.
What is the tab character in Python?
Tab character, also belongs to the situation of "the writing is a combination of two characters, but the meaning is only one character". It is written as a combination of a backslash and the letter t, that is, "\t", and t means table. Its meaning is a character called tab. It should be noted that the tab character only works within quotation marks ('\t' or "\t", but not '\t"), and will be regarded as a character.
Run the following code, you should understand what the tab character is:
1# The tab character is written as \t, and its function is to align the columns of the table.
2 print("Student ID\t Name\tChinese\tMathematics\tEnglish")
3 print("2019001\tCao Cao\t99\t\t88\t\t0")
4 print("2019002\ tZhou Yu\t92\t\t45\t\t93")
5 print("2019008\tHuang Gai\t77\t\t82\t\t100")
The above code The output result is:
Student ID Name Chinese Mathematics English
2019001 Cao Cao 99 88 0
2019002 Zhou Yu 92 45 93
2019008 Huang Gai 77 82 100
Let’s look at another example:
print("I'm Bob, what is your name?")
The output result of the above code is:
I'm Bob, what is your name?
What if you want to output I'm Bob, what is your name? (there are four spaces between the two sentences)? In the print statement what Typed 4 spaces before? Is it OK? No, these 4 spaces are spaces in the statement, not spaces in the output content.
Use tab characters to solve:
At this time The statement should be print("I'm Bob, what is your name?")
The output result is: I'm Bob, what is your name?
It is worth noting that : Mixing the four spaces manually entered with the tabs on the keyboard will result in an error in the program. Do not confuse the two!
The above is the detailed content of What is Python tab character. For more information, please follow other related articles on the PHP Chinese website!