Skip to content

Commit 23e37e5

Browse files
committed
Added string examples
1 parent ce0fbe0 commit 23e37e5

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"source": [
6+
"String Syntax\r\n",
7+
"-------------\r\n",
8+
"\r\n",
9+
"* Strings are enclosed in single or double quotes"
10+
],
11+
"metadata": {}
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 4,
16+
"source": [
17+
"# correct approach\r\n",
18+
"course = 'Python'\r\n",
19+
"print(course)\r\n",
20+
"topic = \"Python Essentials\"\r\n",
21+
"print(topic)"
22+
],
23+
"outputs": [
24+
{
25+
"output_type": "stream",
26+
"name": "stdout",
27+
"text": [
28+
"Python\n",
29+
"Python Essentials\n"
30+
]
31+
}
32+
],
33+
"metadata": {}
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 5,
38+
"source": [
39+
"# Incorrect\r\n",
40+
"course = 'Python\"\r\n",
41+
"topic = \"Python Essentials'"
42+
],
43+
"outputs": [
44+
{
45+
"output_type": "error",
46+
"ename": "SyntaxError",
47+
"evalue": "EOL while scanning string literal (<ipython-input-5-47f0ca9965ed>, line 2)",
48+
"traceback": [
49+
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-5-47f0ca9965ed>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m course = 'Python\"\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
50+
]
51+
}
52+
],
53+
"metadata": {}
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"source": [
59+
"# Strings containing single quotes are enclosed in double quotes\r\n",
60+
"bike_store = 'Joe's\r\n",
61+
"print(bike_store)"
62+
],
63+
"outputs": [
64+
{
65+
"output_type": "error",
66+
"ename": "SyntaxError",
67+
"evalue": "invalid syntax (<ipython-input-3-f4fd6a10cabb>, line 2)",
68+
"traceback": [
69+
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-3-f4fd6a10cabb>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m bike_store = 'Joe's\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
70+
]
71+
}
72+
],
73+
"metadata": {}
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": 6,
78+
"source": [
79+
"bike_store = \"Joe's\"\r\n",
80+
"print(bike_store)\r\n",
81+
"message = 'Hello how are you \"Learner\"'\r\n",
82+
"print(message)"
83+
],
84+
"outputs": [
85+
{
86+
"output_type": "stream",
87+
"name": "stdout",
88+
"text": [
89+
"Joe's\n"
90+
]
91+
}
92+
],
93+
"metadata": {}
94+
}
95+
],
96+
"metadata": {
97+
"orig_nbformat": 4,
98+
"language_info": {
99+
"name": "python",
100+
"version": "3.9.4",
101+
"mimetype": "text/x-python",
102+
"codemirror_mode": {
103+
"name": "ipython",
104+
"version": 3
105+
},
106+
"pygments_lexer": "ipython3",
107+
"nbconvert_exporter": "python",
108+
"file_extension": ".py"
109+
},
110+
"kernelspec": {
111+
"name": "python3",
112+
"display_name": "Python 3.9.4 64-bit"
113+
},
114+
"interpreter": {
115+
"hash": "63fd5069d213b44bf678585dea6b12cceca9941eaf7f819626cde1f2670de90d"
116+
}
117+
},
118+
"nbformat": 4,
119+
"nbformat_minor": 2
120+
}

0 commit comments

Comments
 (0)