Add split_lines snippet
This commit is contained in:
17
snippets/split_lines.md
Normal file
17
snippets/split_lines.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: split_lines
|
||||||
|
tags: string,beginner
|
||||||
|
---
|
||||||
|
|
||||||
|
Splits a multiline string into a list of lines.
|
||||||
|
|
||||||
|
Use `str.split()` and `'\n'` to match line breaks and create a list.
|
||||||
|
|
||||||
|
```py
|
||||||
|
def split_lines(str):
|
||||||
|
str.split('\n')
|
||||||
|
```
|
||||||
|
|
||||||
|
```py
|
||||||
|
split_lines('This\nis a\nmultiline\nstring.\n') # 'This\nis a\nmultiline\nstring.\n'
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user