What does tab character mean in python

爱喝马黛茶的安东尼
Release: 2019-08-01 14:06:08
Original
15885 people have browsed it

What does tab character mean in python

#What is the tab character in Python?

The 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.

Related recommendations :《Python Video Tutorial

Run the following code, you should understand what the tab character is:

#制表符的写法是\t,作用是对齐表格的各列。
print("学号\t姓名\t语文\t数学\t英语")
print("2019001\t曹操\t99\t\t88\t\t0")
print("2019002\t周瑜\t92\t\t45\t\t93")
print("2019008\t黄盖\t77\t\t82\t\t100")
Copy after login

The output result of the above code is:

学号 姓名 语文 数学 英语
2019001 曹操 99 88 0
2019002 周瑜 92 45 93
2019008 黄盖 77 82 100
Copy after login

Let’s look at another example:

print("I'm Bob,what is your name?")
Copy after login

The output result of the above code is:

I'm Bob,what is your name?
Copy after login

If you want to output I'm Bob, what is your name? (two sentences) There are four spaces in the middle) What should I do? Type 4 spaces before the print statement what? OK? No, these 4 spaces are spaces in the statement, not spaces in the output content.

Use Tab characters to solve:

The statement at this time should be

print("I'm Bob,\twhat is your name?")
Copy after login

The output result is:

I'm Bob, what is your name?
Copy after login

It is worth noting: manually enter four spaces and the If the four spaces entered by tab are mixed together, an error will be reported in the program. Do not confuse the two!

The above is the detailed content of What does tab character mean in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template