Python split nebo

Příklady kódu

17
0

N

string = 'James Smith Bond'
x = string.split(' ') #Splits every ' ' (space) in the string to a list
# x = ['James','Smith','Bond']
print('The name is',x[-1],',',x[0],x[-1])
9
0

N

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

N

>>> '1,2,3'.split(',')
['1', '2', '3']
>>> '1,2,3'.split(',', maxsplit=1)
['1', '2,3']
>>> '1,2,,3,'.split(',')
['1', '2', '', '3', '']
5
0

N

str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
str = str.split(',')
print(str) # Output ['Lorem; ipsum. dolor sit amet', ' consectetur adipiscing elit.']

import re
str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
str = re.split(r';|,|\.', str)
print(str) # Output ['Lorem', ' ipsum', ' dolor sit amet', ' consectetur adipiscing elit', '']

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
..................................................................................................................