First of all, I would like to raise a question as follows.
With Python program code:
print("I'm Bob. What's your name?")
The output of the previous line is as follows:
I’m Bob. What’s your name?
The output above does not wrap. If you want to wrap before what, the effect is:
What’s your name?
What should we do?
Knock back before what, OK? No, the effect of this carriage return is to wrap the statement, not the output.
The solution of using newline character
The solution to this problem is to insert a newline before what. It is written as follows:
print("I'm Bob.\nWhat's your name?")
Have you noticed the word in front of what? It’s a character combination, a combination of backslashes and n letters. However, the meaning of this combination is only one character, that is, the newline character.
Again, it’s a combination of two characters in writing, but only one character in meaning.
In Python language, in addition to the newline character, there are many cases where “the writing method is a combination of two characters, but the meaning is only one character”, and the tab character is one of them.
Tab also belongs to the situation that “the writing method is a combination of two characters, but the meaning is only one character”. It’s written as “ T”, a combination of backslash and T, and t means table. It means a character, called a tab. Its function is to align the columns of the table data. Run the following code, you should understand what tab is.
#The table-making character is written as \t and serves to align the columns of the table. print("number\tname\t-a\t-b\t-c") print("2017001\t1\t99\t\t88\t\t0") print("2017002\t2\t92\t\t45\t\t93") print("2017008\t3\t77\t\t82\t\t100")
Running the above code produces the following output:
Student number: Chinese, mathematics, English
2017001 Cao Cao 99 88 0
2017002 Zhou Yu 92 45 93
2017008 Huang Gai 77 82 100
note that the writing of line breaks and tabs only works within quotation marks and is considered a character.
- How to Fix Errors encountered in executing Python scripts with command line parameters
- Python: LeetCode 43 Multiply Strings
- Python time tuples are converted to timestamps, strings
- How does Python output colored fonts in the CMD command line window
- [Solved] Python matplotlib Error: RuntimeError: In set_size: Could not set the fontsize…
- [Solved] Error Mixed spaces and tabs no-mixed-spaces-and-tabs
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Pychar can’t connect to Python console, but it can run. Py file, and Anaconda’s command line can run Python command
- Python_Syntax error: unexpected character after line continuation character
- Python: How to Reshape the data in Pandas DataFrame
- [Solved] pycharm Import New Project Error: cannot set up a python sdk
- An introduction to sys modules in Python and how packages are imported and used
- How to Fix keyerror in Python dictionary lookup
- [Solved] Windows10 Pycharm Use Virtual Environment Error: Cannot set up a python SDK
- Python: How to Auto Add Watermark to PDF
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- Python: How to Solve mysqlclient Install Error in Mac
- [CHM] Python: How to Extract CHM Data
- How to Fix “HTTP error 403: forbidden” in Python 3. X
- How to Fix Python reading large local file memory error