In [1]:
s_blank = 'one two     three\nfour\tfive'
print(s_blank)


one two     three
four	five

In [2]:
print(s_blank.split())


['one', 'two', 'three', 'four', 'five']

In [3]:
print(type(s_blank.split()))


<class 'list'>

In [4]:
s_comma = 'one,two,three,four,five'

In [5]:
print(s_comma.split(','))


['one', 'two', 'three', 'four', 'five']

In [6]:
print(s_comma.split('three'))


['one,two,', ',four,five']

In [7]:
print(s_comma.split(',', 2))


['one', 'two', 'three,four,five']

In [8]:
s_lines = 'one\ntwo\nthree\nfour'
print(s_lines)


one
two
three
four

In [9]:
print(s_lines.split('\n', 1))


['one', 'two\nthree\nfour']

In [10]:
print(s_lines.split('\n', 1)[0])


one

In [11]:
print(s_lines.split('\n', 1)[1])


two
three
four

In [12]:
print(s_lines.split('\n', 1)[-1])


two
three
four

In [13]:
print(s_lines.split('\n', 2)[-1])


three
four

In [14]:
print(s_lines.rsplit('\n', 1))


['one\ntwo\nthree', 'four']

In [15]:
print(s_lines.rsplit('\n', 1)[0])


one
two
three

In [16]:
print(s_lines.rsplit('\n', 1)[1])


four

In [17]:
print(s_lines.rsplit('\n', 2)[0])


one
two

In [18]:
s_lines_multi = '1 one\n2 two\r\n3 three\n'
print(s_lines_multi)


1 one
2 two
3 three


In [19]:
print(s_lines_multi.split())


['1', 'one', '2', 'two', '3', 'three']

In [20]:
print(s_lines_multi.split('\n'))


['1 one', '2 two\r', '3 three', '']

In [21]:
print(s_lines_multi.splitlines())


['1 one', '2 two', '3 three']

In [22]:
print(s_lines_multi.splitlines(True))


['1 one\n', '2 two\r\n', '3 three\n']

In [23]:
l = ['one', 'two', 'three']

In [24]:
print(','.join(l))


one,two,three

In [25]:
print('\n'.join(l))


one
two
three

In [26]:
print(''.join(l))


onetwothree

In [27]:
s = 'abcdefghij'

In [28]:
print(s[:5])


abcde

In [29]:
print(s[5:])


fghij

In [30]:
s_tuple = s[:5], s[5:]

In [31]:
print(s_tuple)


('abcde', 'fghij')

In [32]:
print(type(s_tuple))


<class 'tuple'>

In [33]:
s_first, s_last = s[:5], s[5:]

In [34]:
print(s_first)


abcde

In [35]:
print(s_last)


fghij

In [36]:
s_first, s_second, s_last = s[:3], s[3:6], s[6:]

In [37]:
print(s_first)


abc

In [38]:
print(s_second)


def

In [39]:
print(s_last)


ghij

In [40]:
half = len(s) // 2
print(half)


5

In [41]:
s_first, s_last = s[:half], s[half:]

In [42]:
print(s_first)


abcde

In [43]:
print(s_last)


fghij

In [44]:
print(s_first + s_last)


abcdefghij