-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSplit_String.py
More file actions
18 lines (13 loc) · 824 Bytes
/
Split_String.py
File metadata and controls
18 lines (13 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
str1 = 'Cysteine helps prevent side effects due to drug reactions and toxic chemicals'
str1.split(sep=' ')
# ['Cysteine', 'helps', 'prevent', 'side', 'effects', 'due', 'to', 'drug', 'reactions', 'and', 'toxic', 'chemicals']
str1.split(sep=' ', maxsplit=2) # Left split
# ['Cysteine', 'helps', 'prevent side effects due to drug reactions and toxic chemicals']
str1.rsplit(sep=' ', maxsplit=2) # Right split
# ['Cysteine helps prevent side effects due to drug reactions and', 'toxic', 'chemicals']
str2 = 'Cysteine \nhelps prevent side effects due to drug reactions and toxic chemicals'
print(str2)
# Cysteine
# helps prevent side effects due to drug reactions and toxic chemicals
str2.splitlines() # Split string at line boundaries
# ['Cysteine ', 'helps prevent side effects due to drug reactions and toxic chemicals']