Home >Backend Development >Python Tutorial >What is the newline character in Python?
#What is the newline character in python?
#The python newline character is "\n".
Windows newline character is '\r\n',
Unix/Linux newline character is '\n',
Mac newline character is ' \r',
In python, newline characters are processed uniformly and defined as "\n".
Use "\" for line break input:
1. In python, Python uses backslash ("\") as the line continuation character ( newline character), here we take python3.5 as an example. First run the terminal or cmd command line (under windows) and execute the python3.5 command.
#2. Then enter the content as shown below. It is a string that outputs hello world!. But "" is used here for line breaks.
3. This line wrapping method can also be performed in the editor. Here we take vim as an example. Enter code similar to the above picture and save it as a t.py script file. .
#4. Execute the following command in bash, it can also be executed.
#5. If you do not want to use commands, you can add permissions to the python script. First, specify the script interpreter as python in the script file. Add the following line to the above t.py script file: #!/usr/bin/env python.
6. Then execute the following command to add executable permissions to t.py, chmod 755 t.py. Execute the following command to execute the python script, ./t.py, which can also be executed.
Recommended tutorial: "python tutorial"
The above is the detailed content of What is the newline character in Python?. For more information, please follow other related articles on the PHP Chinese website!