Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (6.1k points)
I want to know all about the join method.

1 Answer

0 votes
by (11.7k points)

The join() method is used to return a string, concatenated with iterable(looping) elements.

Note: If there occurs a non-string value during iteration, a TypeError exception is raised. 

code: 

list_a = ['1','2','3','4']  

 

x = "-" 

 

# joins elements of list_a by '-'  

# and stores in sting x

x = x.join(list_a)  

 

# join use to join a list of  

# strings to a separate x  

print(x) 

Explanation: Elements of the list are joined by '-' and are getting stored in x. Join is used to join a list of strings to separator x. Hence, we get the string.

Want to learn Python, check out this Python Tutorial from Intellipaat.

Related questions

0 votes
1 answer
asked Feb 17, 2021 in Python by adhiraj (4k points)
0 votes
1 answer
asked Sep 23, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...