⊗pyPmIBSS 180 of 208 menu

Splitting Strings in Python

split rsplit partition rpartition join

Given a string:

txt = 'a/b/c/d'

Write the code to get the following result:

['a', 'b', 'c', 'd']

Given a string:

txt = 'a.b.c.d'

Write the code to get the following result:

['a.b.c', 'd']

Given a string:

txt = 'ab%cd%'

Write the code to get the following result:

('ab', '%', 'cd%')

Given a string:

txt = '2025-12-31'

Write the code to get the following result:

('2025-12', '-', '31')

Given a string:

txt = '2025-12-31'

Write the code to get the following result:

('2025-12', '-', '31')

Given a list:

lst = ['a', 'b', 'c', 'd']

Write the code to get the following string:

'abcd'

Given a list:

lst = ['2025', '31', '12']

Write the code to get the following string:

'2025/31/12'

Given a list:

lst = [1, 2, 3]

Write the code to get the following string:

'123'
byenru