0
Q:

how to split word in python

def split(word): 
    return [char for char in word]  
      
# Driver code 
word = 'geeks'
print(split(word)) 

#Output ['g', 'e', 'e', 'k', 's']
10
# Default splits at whitespace
txt = "Welcome to the jungle, baby!"
txt.split()
# Output:
# ["Welcome", "to", "the", "jungle," "baby!"]

# You can specify where to split
txt = "Welcome to the jungle, baby!"
txt.split(", ")
# Output:
# ["Welcome to the jungle", "baby!"]
72
file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
15
text= "I am Batman"
splitted_text= text.split()

Print(splitted_text)
0

New to Communities?

Join the community