![]() ![]() #applying list method to the individual elements of the list string1 #converting string1 into a list of strings Take a look at the given example code below. What if we need a list of characters present in a string? In that case, direct type conversion from string to list in Python using the list() method does the job for us.Ĭertainly, if the input string is something like “abcd”, typecasting the string into a list using the list() method gives us a list having the individual characters ‘a’, ‘b’, ‘c’, ‘d’ as its elements. Hence though we have not mentioned the separator parameter, the split() method gives us a list of the respective strings.By default, if we do not pass anything to the split() method it splits up the string based on the position of spaces In our code, the words were separated by spaces. split() is used to split a string into a list based on the given separator. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |