Skip to content

Commit df3a748

Browse files
authored
Add files via upload
1 parent 1be2c45 commit df3a748

38 files changed

+6557
-0
lines changed

1-Python Basics/1.0-basic.ipynb

Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### Syntax and Semantics in Python\n",
8+
"Video Outline:\n",
9+
"- Single line Comments and multiline comments \n",
10+
"- Definition of Syntax and Semantics\n",
11+
"- Basic Syntax Rules in Python\n",
12+
"- Understanding Semantics in Python\n",
13+
"- Common Syntax Errors and How to Avoid Them\n",
14+
"- Practical Code Examples"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"Syntax refers to the set of rules that defines the combinations of symbols that are considered to be correctly structured programs in a language. In simpler terms, syntax is about the correct arrangement of words and symbols in a code.\n",
22+
"\n",
23+
"Semantics refers to the meaning or the interpretation of the symbols, characters, and commands in a language. It is about what the code is supposed to do when it runs."
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 1,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"Krish\n",
36+
"Naik\n"
37+
]
38+
}
39+
],
40+
"source": [
41+
"## Basic Syntax Rules In Python\n",
42+
"## Case sensitivity- Python is case sensitive\n",
43+
"\n",
44+
"name=\"Krish\"\n",
45+
"Name=\"Naik\"\n",
46+
"\n",
47+
"print(name)\n",
48+
"print(Name)\n"
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"metadata": {},
54+
"source": [
55+
"### Indentation\n",
56+
"Indentation in Python is used to define the structure and hierarchy of the code. Unlike many other programming languages that use braces {} to delimit blocks of code, Python uses indentation to determine the grouping of statements. This means that all the statements within a block must be indented at the same level."
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 2,
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"32\n",
69+
"32\n"
70+
]
71+
}
72+
],
73+
"source": [
74+
"## Indentation\n",
75+
"## Python uses indentation to define blocks of code. Consistent use of spaces (commonly 4) or a tab is required.\n",
76+
"\n",
77+
"age=32\n",
78+
"if age>30:\n",
79+
" \n",
80+
" print(age)\n",
81+
" \n",
82+
"print(age)\n"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": 3,
88+
"metadata": {},
89+
"outputs": [
90+
{
91+
"name": "stdout",
92+
"output_type": "stream",
93+
"text": [
94+
"Hello World\n"
95+
]
96+
}
97+
],
98+
"source": [
99+
"## This is a single line comment\n",
100+
"print(\"Hello World\")"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 5,
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"name": "stdout",
110+
"output_type": "stream",
111+
"text": [
112+
"43\n"
113+
]
114+
}
115+
],
116+
"source": [
117+
"## Line Continuation\n",
118+
"##Use a backslash (\\) to continue a statement to the next line\n",
119+
"\n",
120+
"total=1+2+3+4+5+6+7+\\\n",
121+
"4+5+6\n",
122+
"\n",
123+
"print(total)\n"
124+
]
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": 6,
129+
"metadata": {},
130+
"outputs": [
131+
{
132+
"name": "stdout",
133+
"output_type": "stream",
134+
"text": [
135+
"15\n"
136+
]
137+
}
138+
],
139+
"source": [
140+
"## Multiple Statements on a single line\n",
141+
"x=5;y=10;z=x+y\n",
142+
"print(z)"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": 7,
148+
"metadata": {},
149+
"outputs": [],
150+
"source": [
151+
"##Understand Semnatics In Python\n",
152+
"# variable assignment\n",
153+
"age=32 ##age is an integer\n",
154+
"name=\"Krish\" ##name is a string"
155+
]
156+
},
157+
{
158+
"cell_type": "code",
159+
"execution_count": 10,
160+
"metadata": {},
161+
"outputs": [
162+
{
163+
"data": {
164+
"text/plain": [
165+
"int"
166+
]
167+
},
168+
"execution_count": 10,
169+
"metadata": {},
170+
"output_type": "execute_result"
171+
}
172+
],
173+
"source": [
174+
"\n",
175+
"\n",
176+
"type(age)"
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": 9,
182+
"metadata": {},
183+
"outputs": [
184+
{
185+
"data": {
186+
"text/plain": [
187+
"str"
188+
]
189+
},
190+
"execution_count": 9,
191+
"metadata": {},
192+
"output_type": "execute_result"
193+
}
194+
],
195+
"source": [
196+
"type(name)"
197+
]
198+
},
199+
{
200+
"cell_type": "code",
201+
"execution_count": 12,
202+
"metadata": {},
203+
"outputs": [
204+
{
205+
"name": "stdout",
206+
"output_type": "stream",
207+
"text": [
208+
"<class 'int'>\n",
209+
"<class 'str'>\n"
210+
]
211+
}
212+
],
213+
"source": [
214+
"## Type Inference\n",
215+
"variable=10\n",
216+
"print(type(variable))\n",
217+
"variable=\"Krish\"\n",
218+
"print(type(variable))"
219+
]
220+
},
221+
{
222+
"cell_type": "code",
223+
"execution_count": 14,
224+
"metadata": {},
225+
"outputs": [
226+
{
227+
"name": "stdout",
228+
"output_type": "stream",
229+
"text": [
230+
"32\n"
231+
]
232+
}
233+
],
234+
"source": [
235+
"age=32\n",
236+
"if age>30:\n",
237+
" print(age)"
238+
]
239+
},
240+
{
241+
"cell_type": "code",
242+
"execution_count": 15,
243+
"metadata": {},
244+
"outputs": [
245+
{
246+
"ename": "NameError",
247+
"evalue": "name 'b' is not defined",
248+
"output_type": "error",
249+
"traceback": [
250+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
251+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
252+
"Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m a\u001b[38;5;241m=\u001b[39m\u001b[43mb\u001b[49m\n",
253+
"\u001b[1;31mNameError\u001b[0m: name 'b' is not defined"
254+
]
255+
}
256+
],
257+
"source": [
258+
"## Name Error\n",
259+
"a=b"
260+
]
261+
},
262+
{
263+
"cell_type": "code",
264+
"execution_count": 17,
265+
"metadata": {},
266+
"outputs": [
267+
{
268+
"name": "stdout",
269+
"output_type": "stream",
270+
"text": [
271+
"Correct Indentation\n",
272+
"This will print\n",
273+
"Outside the if block\n"
274+
]
275+
}
276+
],
277+
"source": [
278+
"## Code exmaples of indentation\n",
279+
"if True:\n",
280+
" print(\"Correct Indentation\")\n",
281+
" if False:\n",
282+
" print(\"This ont print\")\n",
283+
" print(\"This will print\")\n",
284+
"print(\"Outside the if block\")"
285+
]
286+
},
287+
{
288+
"cell_type": "markdown",
289+
"metadata": {},
290+
"source": [
291+
"### Conclusion:\n",
292+
"Understanding the syntax and semantics of Python is crucial for writing correct and meaningful programs. Syntax ensures the code is properly structured, while semantics ensures the code behaves as expected. Mastering these concepts will help in writing efficient and error-free Python code."
293+
]
294+
},
295+
{
296+
"cell_type": "markdown",
297+
"metadata": {},
298+
"source": []
299+
}
300+
],
301+
"metadata": {
302+
"kernelspec": {
303+
"display_name": "Python 3",
304+
"language": "python",
305+
"name": "python3"
306+
},
307+
"language_info": {
308+
"codemirror_mode": {
309+
"name": "ipython",
310+
"version": 3
311+
},
312+
"file_extension": ".py",
313+
"mimetype": "text/x-python",
314+
"name": "python",
315+
"nbconvert_exporter": "python",
316+
"pygments_lexer": "ipython3",
317+
"version": "3.12.0"
318+
}
319+
},
320+
"nbformat": 4,
321+
"nbformat_minor": 2
322+
}

0 commit comments

Comments
 (0)