Andy
0
Q:

.join in python 3

# example of join() function in python

numList = ['1', '2', '3', '4']
separator = ', '
print(separator.join(numList))
15
# Python program to demonstrate the 
# use of join function to join list 
# elements with a character. 
  
list1 = ['1','2','3','4']  
  
s = "-"
  
# joins elements of list1 by '-' 
# and stores in sting s 
s = s.join(list1) 
  
# join use to join a list of 
# strings to a separator s 
print(s) 

OUTPUT:
  1-2-3-4
8
myTuple = ("John", "Peter", "Vicky")
x = "#".join(myTuple)
print(x) #		John#Peter#Vicky
4

myTuple = ("John", "Peter", "Vicky")

x = "#".join(myTuple)

    
print(x) 
0
# Joins all items in a list or tuple, using a specific separator
lst = ['a', 'b', 'c']
joinedLst = ', '.join(lst)
print(x) # Prints 'a, b, c'
0
# Python program to demonstrate the 
# use of join function to join list 
# elements without any separator. 
  
# Joining with empty separator 
list1 = ['g','e','e','k', 's']  
print("".join(list1)) 

#output: "geeks"
0

New to Communities?

Join the community