Home  >  Article  >  Backend Development  >  How to wrap code in python

How to wrap code in python

藏色散人
藏色散人Original
2019-11-05 11:07:1429388browse

How to wrap code in python

How to wrap code in Python?

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.

Recommended: "python tutorial"

Method 1. Use "\" for line break input:

1. In python, Python uses reverse Slash ("\") is used as a line continuation character (newline character). Here, python3.5 is used as an example. First run the terminal or cmd command line (under windows) and execute the python3.5 command.

How to wrap code in python

#2. Then enter the content as shown below. It is a string that outputs hello world!. But "\" is used here for line breaks.

How to wrap code in python

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

How to wrap code in python

4. Execute the following command in bash, it can also be executed.

How to wrap code in python

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

How to wrap code in 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.

How to wrap code in python

Method 2. Special cases

1. In the Python language, expressions in parentheses, square brackets or curly brackets are completely unnecessary. Use "\" to break new lines, but of course you don't have to use it. For example, the code shown below. is the calculation of a simple arithmetic expression. At this time, you don't need to use "\" to wrap the expression in parentheses, just press Enter to wrap automatically.

How to wrap code in python

#2. You can also make such input in the editor. The picture below is the input in vim without using "\".

How to wrap code in python

The above is the detailed content of How to wrap code in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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