>>> sentence = ['this','is','a','sentence']
>>> '-'.join(sentence)
'this-is-a-sentence'
join() python
# example of join() function in python
numList = ['1', '2', '3', '4']
separator = ', '
print(separator.join(numList))
N
>>> sentence = ['this','is','a','sentence']
>>> '-'.join(sentence)
'this-is-a-sentence'
N
# example of join() function in python
numList = ['1', '2', '3', '4']
separator = ', '
print(separator.join(numList))
N
list = ['Add', 'Grepper', 'Answer']
Inline
> joined = " ".join(list)
> Add Grepper Answer
Variable
> seperator = ", "
> joined = seperator.join(list)
> Add, Grepper, Answer
N
str1 = “Hello”
str2 = “World”
str1 + str2
N
# 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
# 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
N
"seperator".join(list/tuple)
# Мөрийн арга .join() нь мөрүүдийн жагсаалтыг хооронд нь холбож, хүссэн хязгаарлагчтай холбосон шинэ мөр үүсгэнэ.
# .join() аргыг хязгаарлагч дээр ажиллуулж, нэгтгэх мөрийн массивыг аргумент болгон дамжуулдаг.
x = "-".join(["Codecademy", "is", "awesome"])
print(x)
# Prints: Codecademy-is-awesome
připojte se funkce python
w=["as","3e","1"]
a='vf'.join(w)
print(a)
//displays string asvf3evf1