How to wrap in python code

In the process of writing code, often encountered a long line of code. In order to make the code look neat and clean, you need to divide one line of code into multiple lines to write. There are two small tricks in Python to achieve this function:

  1. Use backslashes to link multiple lines of code, sample output: 55
a=22+\
33
printa
  1. Enclosed in parentheses, sample output: 55
a=(22+33)
printa

Tip: There is another simple method for writing a long string into multiple lines: use three single quotes, but this method is only useful for strings. The following code output:

32+45
a='''32+45'''
printa

Summary supplement:

How to write code in python?

The Windows newline character is'\r\n',

The newline character for Unix/Linux is'\n',

The newline character for Mac is'\r',

In python, the newline character is processed uniformly and defined as'\n.

So far, this article on how to wrap lines in python code is introduced. For more related Python code how to wrap lines, please search for previous articles on ZaLou.Cn or continue to browse related articles below. Hope you will support ZaLou.Cn more in the future. !

Recommended Posts

How to wrap in python code
How to comment python code
How to use code running assistant in python
How to set code auto prompt in python
python how to view webpage code
How to omit parentheses in Python
How to write classes in python
How to filter numbers in python
How to read Excel in Python
How to view errors in python
How to write return in python
How to understand variables in Python
How to clear variables in python
How to use SQLite in Python
How to use and and or in Python
How to delete cache files in python
How to represent null values in python
How to save text files in python
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
How to write try statement in python
How to define private attributes in Python
How to add custom modules in Python
How to understand global variables in Python
How to view installed modules in python
How to open python in different systems
How to sort a dictionary in python
How to add background music in python
How to represent relative path in python
How to use the round function in python
How to use the zip function in Python
How to program based on interfaces in Python
How to install python in ubuntu server environment
How to simulate gravity in a Python game
How to use the format function in python
Teach you how to write games in python
How to delete files and directories in python
How to install the downloaded module in python
How to write a confession program in python
Python how to move the code collectively right
How to perform continuous multiplication calculation in python
Python code to find bugs (2)
Python code to find bugs(7)
Python code to find bugs(4)
Python code to find bugs (3)
Python code to find bugs(9)
How to write Pythonic code
How to learn python quickly
How to uninstall python plugin
Python code to find bugs(6)
Python code to find bugs (1)
Python code to find bugs(8)
How to understand python objects
Python code to find bugs(5)
How to use python tuples
How to understand the introduction of packages in Python
How to understand a list of numbers in python
Example of how to automatically download pictures in python
How to save IE as an attachment in python