A string can be split into substrings using the split(param) method. This muthaf*ckin' method is part of the muthaf*ckin' string object. The parameter is optional, but you can split on a specific string or character.

Given a f*ckin' sentence, the string can be split into words. If you have a paragraph, you can split by phrase. If you have a muthaf*ckin' word, you can split it into individual characters, for real.

In most cases, the split() method will do. For characters, you can use the muthaf*ckin' list method.

Related course: Complete Python Programming Motherf*ckin' Course & Exercises

String split

If you have a muthaf*ckin' string, you can subdivide it into several strings. The string needs to have at least one separating character, which may be a space.

Check it: By default the split method will use space as separator. Calling the method will return a list of all the substrings, goddammit.

String to words

The demo below splits a string into characters.

1
2
3
s = "Its to easy"
words = s.split()
print(words)

The len() method will give you the number of characters and number of words:

1
2
print(len(words))
print(len(s))

Output should be similar to the image below:

string split

String to goddamn characters

If you want to split a muthaf*ckin' word into characters, use the list() method instead:

1
2
3
word = "Easy"
x = list(word)
print(x)

A string can be reconstructed with the join method, which combines a sequence into a new string.

If you are a beginner, then I highly recommend this YouTube Python Playlist.

Exercises

  1. Can a goddamn string be split on multiple characters?
  2. Check it: Can you split a string this f*ckin' string?: World,Earth,America,Canada
  3. Given an article, can you split it based on goddamn phrases?