Skip to content

Commit 3ecdbcf

Browse files
committed
Create a List of Strings
1 parent 23bb669 commit 3ecdbcf

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed

Array/Create a List of Strings .ipynb

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"['Geeks', 'For', 'Geeks']\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"a: list[str] = [\"Geeks\", \"For\", \"Geeks\"]\n",
18+
"print(a)"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"## Using list() Function"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 2,
31+
"metadata": {},
32+
"outputs": [
33+
{
34+
"name": "stdout",
35+
"output_type": "stream",
36+
"text": [
37+
"['geeks', 'For', 'geeks']\n"
38+
]
39+
}
40+
],
41+
"source": [
42+
"b = list([\"geeks\", \"For\", \"geeks\"])\n",
43+
"print(b)"
44+
]
45+
},
46+
{
47+
"cell_type": "markdown",
48+
"metadata": {},
49+
"source": [
50+
"## Using List Comprehension"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 3,
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"name": "stdout",
60+
"output_type": "stream",
61+
"text": [
62+
"['gfg0', 'gfg1', 'gfg2']\n"
63+
]
64+
}
65+
],
66+
"source": [
67+
"d = ['gfg' + str(i) for i in range(3)]\n",
68+
"print(d)"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"metadata": {},
74+
"source": [
75+
"## Using a Loop With append()"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"metadata": {},
82+
"outputs": [],
83+
"source": [
84+
"c: list[str] = []\n",
85+
"for i in range(3):\n",
86+
" c.append(\"gfg\"+str(i))"
87+
]
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {},
92+
"source": [
93+
"## Using extend() Method"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": 5,
99+
"metadata": {},
100+
"outputs": [
101+
{
102+
"name": "stdout",
103+
"output_type": "stream",
104+
"text": [
105+
"['geeks', 'for', 'geeks', 'gfg']\n"
106+
]
107+
}
108+
],
109+
"source": [
110+
"e = [\"geeks\", \"for\"]\n",
111+
"e.extend([\"geeks\", \"gfg\"])\n",
112+
"print(e)"
113+
]
114+
},
115+
{
116+
"cell_type": "markdown",
117+
"metadata": {},
118+
"source": [
119+
"## Using + Operator to Combine Lists"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": 6,
125+
"metadata": {},
126+
"outputs": [
127+
{
128+
"name": "stdout",
129+
"output_type": "stream",
130+
"text": [
131+
"['geeks', 'for', 'geeks', 'gfg']\n"
132+
]
133+
}
134+
],
135+
"source": [
136+
"f = [\"geeks\", \"for\"]\n",
137+
"f = f + [\"geeks\", \"gfg\"]\n",
138+
"print(f)"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"metadata": {},
144+
"source": [
145+
"## Using * Operator for Repeating Strings"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": 7,
151+
"metadata": {},
152+
"outputs": [
153+
{
154+
"name": "stdout",
155+
"output_type": "stream",
156+
"text": [
157+
"['gtg', 'gtg', 'gtg']\n"
158+
]
159+
}
160+
],
161+
"source": [
162+
"g = [\"gtg\"] * 3\n",
163+
"print(g)"
164+
]
165+
}
166+
],
167+
"metadata": {
168+
"kernelspec": {
169+
"display_name": "Python 3",
170+
"language": "python",
171+
"name": "python3"
172+
},
173+
"language_info": {
174+
"codemirror_mode": {
175+
"name": "ipython",
176+
"version": 3
177+
},
178+
"file_extension": ".py",
179+
"mimetype": "text/x-python",
180+
"name": "python",
181+
"nbconvert_exporter": "python",
182+
"pygments_lexer": "ipython3",
183+
"version": "3.12.9"
184+
}
185+
},
186+
"nbformat": 4,
187+
"nbformat_minor": 2
188+
}

0 commit comments

Comments
 (0)