+ 1
What is the use of .join and .split in python
I have seen it in several codes and challenges, but I do not know what it means, and I do not remember having read it in any lesson
1 Respuesta
+ 25
.split() method is used to split string into lists...
eg:
str = "python is great"
str.split(" ") will make it
['python', 'is', 'great']...
👆here split separates the string str by space
eg 2:
str = "python"
str.split() will make it
['python']
syntax is : str.split(separator, maxsplit)
.join() is reverse of .split()
it will make the list back to string
eg :
s =['python', 'is', 'great']
print("_".join(s)) will make it
python_is_great
syntax is : str.join(iterable)
check out this link
https://www.geeksforgeeks.org/python-program-split-join-string/