We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2615b43 commit 298dec3Copy full SHA for 298dec3
Python-3/basic_examples/strings/string_append.py
@@ -0,0 +1,24 @@
1
+def str_append(s, n):
2
+ output = ''
3
+ i = 0
4
+ while i < n:
5
+ output += s
6
+ i = i + 1
7
+ return output
8
+
9
10
+def str_append_list_join(s, n):
11
+ l1 = []
12
13
14
+ l1.append(s)
15
+ i += 1
16
+ return ''.join(l1)
17
18
19
+if __name__ == "__main__":
20
+ print('Append using + operator:', str_append('Hi', 10))
21
+ print('Append using list and join():', str_append_list_join('Hi', 10))
22
+ # use below for this case, above methods are created so that we can
23
+ # check performance using timeit module
24
+ print('Append using * operator:', 'Hi' * 10)
0 commit comments