split string into words code example
Example 1: split string python
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])
Example 2: split string
const str = 'The quick brown fox jumps over the lazy dog.';
const words = str.split(' ');
console.log(words[3]);
// expected output: "fox"
const chars = str.split('');
console.log(chars[8]);
// expected output: "k"
const strCopy = str.split();
console.log(strCopy);
// expected output: Array ["The quick brown fox jumps over the lazy dog."]