Python rozdělit řetězec podle oddělovače

Příklady kódu

27
0

N

foo = "A B C D"
bar = "E-F-G-H"

# the split() function will return a list
foo_list = foo.split()
# if you give no arguments, it will separate by whitespaces by default
# ["A", "B", "C", "D"]

bar_list = bar.split("-", 3)
# you can specify the maximum amount of elements the split() function will output
# ["E", "F", "G"]
20
0

N

file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
9
0

N

>>> a='Beautiful, is; better*than\nugly'
>>> import re
>>> re.split('; |, |\*|\n',a)
['Beautiful', 'is', 'better', 'than', 'ugly']
1
0

N

>>> "MATCHES__STRING".split("__")
['MATCHES', 'STRING']
-1
0

N

sample_str = "Help developers by donating!"
txt.split(' ')

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................