0
Q:

.join in python

# 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
7
# 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
# the join method in python is works like 
# it joins the the string that you provide to it to a sequence types(lists etc..)
flowers = [
    "Daffodil",
    "Evening Primrose",
    "Hydrangea",
    "Iris",
    "Lavender",
    "Sunflower",
    "Tiger Lilly",
]
print(", ".join(flowers))

# what the sbove code does is it joins all the flowers in list by ', '
# output = Daffodil, Evening Primrose, Hydrangea, Iris, Lavender, Sunflower, Tiger Lilly
1
"seperator".join(list/tuple)
1

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
# 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