-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin method for string
More file actions
50 lines (23 loc) · 1.12 KB
/
join method for string
File metadata and controls
50 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
The line return ''.join(x) is a Python expression
used to convert a list of characters back into a single string.
'' (Empty String):
The '' is the string that you want to use as
a separator between the elements of the list.
In this case, it's an empty string,
so no additional characters will be added between the elements when joining them.
.join(iterable):
The .join() method is a string method in Python.
It takes an iterable (such as a list, tuple, or any sequence of strings)
as an argument and combines all the elements of that iterable into a single string.
Each element of the iterable must be a string.
The List x:
In your code, x is a list of characters (because list(x) was
used to convert the input string into a list). For example:
How It Works:
The join method combines all the characters (
or strings) in the list x into a single string.
Since the separator is an empty string '', it simply concatenates
them together without adding anything in between.
x = ['H', 'e', '*', '*', 'o']
result:
After joining, the list ['H', 'e', '*', '*', 'o'] becomes the string "He**o".