# Line continuation character(\)

The backslash (`\`) is used as a line continuation character in Python. It allows you to split a single line of code into multiple physical lines. This can be helpful when you have long lines of code that exceed the recommended line length limit (usually 79 or 80 characters) to improve readability.

You can use the backslash to split a line wherever it makes logical sense, such as after a comma or an operator. Here's an example:

```python
# Long line split into multiple lines using '\'
result = some_function(arg1, arg2, arg3, arg4) + \
         another_function(arg5, arg6) - \
         yet_another_function(arg7, arg8)
```

You can use the backslash to split long conditional statements across multiple lines:

```python
if not matrix or matrix == [] or \
   not all(isinstance(row, list) for row in matrix) or \
   not all(isinstance(elem, (int, float)) for row in matrix for elem in row):
    raise TypeError('matrix must be a non-empty matrix (list of lists) of integers/floats')
```

By using the backslash, you can continue the logical expression onto the next line without introducing any syntax errors.

It's important to note that the backslash should be the last character on the line. Also, if you're using parentheses, brackets, or braces, you can split the line without using the backslash, as Python automatically assumes line continuation in those cases.

There should not be a space after the backslash (\\) when using it for line continuation. The backslash is used to indicate that the line continues onto the next physical line without any intervening whitespace.

For example, this is the correct usage:

```python
if not matrix or matrix == [] \
   or not all(isinstance(row, list) for row in matrix):
    raise TypeError('matrix must be a matrix (list of lists) '
                    'of integers/floats')
```

In this code snippet, the backslash is placed at the end of the line without any space immediately following it. This ensures that the lines are joined together without any whitespace between them.

Adding a space after the backslash would result in a syntax error. So it's important to omit the space after the backslash when using it for line continuation.

You receive this message when you use a backslash between brackets

```python
2-matrix_divided.py:15:47: E502 the backslash is redundant between brackets
```

the backslash is indeed redundant between brackets.

The error message indicates that the backslash is unnecessary and can be safely removed. The backslash is only required when you want to split a line within brackets, such as parentheses or square brackets, where Python cannot automatically detect the line continuation.

**When you using line continuations in python, you might receive errors like this:**

```python
#Errors not exactly, but looking similar to this
2-matrix_divided.py:16:13: E128 continuation line under-indented for visual indent
2-matrix_divided.py:18:17: E128 continuation line over-indented for visual indent
```

To resolve these errors, you need to ensure that the continuation lines are indented at the same level as the line they are continuing from. In Python, the recommended indentation style is to use 4 spaces for each level of indentation.

Most times it doesn't indent well, and mostly depends on the text editor you are using. Since I use vi, vi workaround is what i know about.

If you're using the `vi` text editor, you can adjust the indentation manually. You can use shift-tab(reduces indentation levels) for other text editor and see if it wil work.

Here's how you can do it:

1. Open the file in `vi` by running the command: `vi` [`filename.py`](http://filename.py) (replace [`filename.py`](http://filename.py) with the actual name of your Python file).
    
2. Move the cursor to the line that needs indentation adjustment.
    
3. Press the `x` key to delete any unwanted spaces or tabs.
    
4. Make sure your cursor is at the start of the line you want to indent and your code it's what starts that particular line
    
5. Press the `i` key to enter the insert mode.
    
6. Press the spacebar key multiple times to add the desired number of spaces for indentation.
    
7. Press the Esc key to exit the insert mode.
    
8. Save the changes and exit `vi` by typing `:wq` and pressing Enter.
    

These steps allow you to manually adjust the indentation in `vi` by inserting the appropriate number of spaces.

Please note that `vi` uses a modal editing approach, so you need to switch to the insert mode (`i`) to make changes.

### Here is the difference between over indent, under indent and the correct thing

**over:**

```python
if not all(isinstance(elem, (int, float))
            for row in matrix for elem in row):
```

**under:**

```python
if not all(isinstance(elem, (int, float))
        for row in matrix for elem in row):
```

**correct:**

```python
if not all(isinstance(elem, (int, float))
           for row in matrix for elem in row):
```
