split()
` function :# Split a string into substrings
my_string = "Hello, World!"
substrings = my_string.split(",")
print("The substrings are:", substrings)
In the above program, we start by assigning the string value `"Hello, World!
"` to the variable `my_string
`. We then use the `split()
` function to split `my_string
` into substrings at each occurrence of the comma `,
`, and assign the resulting substrings to the variable `substrings
`.
Finally, we use the `print()
` function to print the message "The substrings are:" followed by the value of `substrings
`.
When we run the program, it will output the following message :
The substrings are: ['Hello', ' World!']
split()
` function splits the string into substrings based on the delimiter `,
`. The resulting substrings are stored in a list, which is assigned to the variable `substrings
`.