python split string in list code example
Example 1: how to split a string by character in python
def split(word):
return [char for char in word]
# Driver code
word = 'geeks'
print(split(word))
#Output ['g', 'e', 'e', 'k', 's']
Example 2: 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 3: python split list
string = 'this is a python string'
wordList = string.split(' ')
Example 4: python split list
string = "this is a string" # Creates the string
splited_string = string.split(" ") # Splits the string by spaces
print(splited_string) # Prints the list to the console
# Output: ['this', 'is', 'a', 'string']