Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4f983ad

Browse files
Added PyBasics-1.ipynb
1 parent cd1f1ea commit 4f983ad

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed

‎basic/PyBasics-1.ipynb

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Python Keywords\n",
8+
"- Keywords are predefined, reserved words \n",
9+
"- Cannot use a keyword as a variable name, function name\n",
10+
"- used to define the syntax and structure of the Python language\n",
11+
"\n",
12+
"**Python has `35 keywords` >> All the keywords except True, False and None are in lowercase**"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": [
19+
"## Python 35 Keywords\n",
20+
"\n",
21+
"`import` `from` `as` \n",
22+
"\n",
23+
"`if` `else` `elif`\n",
24+
"\n",
25+
"`in` `is` `and` `or` `not`\n",
26+
"\n",
27+
"`for` `while` `break` `continue` `pass`\n",
28+
"\n",
29+
"`def` `return` `raise` `yield`\n",
30+
"\n",
31+
"`try` `except` `finally` `assert`\n",
32+
"\n",
33+
"`global` `nonlocal`\n",
34+
"\n",
35+
"`lambda` `True` `False` `None`\n",
36+
"\n",
37+
"`with` `await` `async` `del` `class`\n"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 1,
43+
"metadata": {},
44+
"outputs": [
45+
{
46+
"name": "stdout",
47+
"output_type": "stream",
48+
"text": [
49+
"\n",
50+
"Here is a list of the Python keywords. Enter any keyword to get more help.\n",
51+
"\n",
52+
"False class from or\n",
53+
"None continue global pass\n",
54+
"True def if raise\n",
55+
"and del import return\n",
56+
"as elif in try\n",
57+
"assert else is while\n",
58+
"async except lambda with\n",
59+
"await finally nonlocal yield\n",
60+
"break for not \n",
61+
"\n"
62+
]
63+
}
64+
],
65+
"source": [
66+
"# Print All Python Keywords\n",
67+
"help(\"keywords\")"
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"metadata": {},
73+
"source": [
74+
"# Python Identifiers\n",
75+
"\n",
76+
"Identifiers are the name given to variables, classes, methods, etc.\n",
77+
"\n",
78+
"`language = 'Python'`\n",
79+
"Here, language is a variable (an identifier) which holds the value 'Python'\n",
80+
"\n",
81+
"\n",
82+
"## Variables\n",
83+
"A `variable` is a container (storage area) to hold data. Exp: `number = 10`\n",
84+
"\n",
85+
"**Variable Naming Conventions**\n",
86+
"- snake_case\n",
87+
"- MACRO_CASE\n",
88+
"- camelCase\n",
89+
"- CapWords\n",
90+
"\n",
91+
"\n",
92+
"## Constants\n",
93+
"A `constant` is a special type of variable whose value cannot (is not) be changed. Exp: PI = 3.14\n",
94+
"\n",
95+
"## Literals\n",
96+
"`Literals` are representations of fixed values in a program. \\\n",
97+
"They can be numbers, characters, or strings, etc. For example, 'Hello, World!', 12, 23.0, 'C', etc.\n",
98+
"\n",
99+
"**Python Literal Types**\n",
100+
" - `Numeric literals: ` can belong to 3 different numerical types: Integer, Float, and Complex. Exp: a = 6 + 9j. \n",
101+
" - `boolean literals:` True, False\n",
102+
" - `Character literals:` are unicode characters enclosed in a quote. Exp: some_character = 'S'\n",
103+
" - `String literals` are sequences of Characters enclosed in quotation marks.\n",
104+
" - `Special literal:` None >> used to specify a null variable. Exp: num = None\n",
105+
" - `Four literal collections:` List literals, Tuple literals, Dict literals, and Set literals.\n",
106+
"\n"
107+
]
108+
},
109+
{
110+
"cell_type": "markdown",
111+
"metadata": {},
112+
"source": [
113+
"# Python Data Types\n",
114+
"\n",
115+
"\n",
116+
"![Python Data Types](imgs/python_data_types.PNG)\n",
117+
"\n",
118+
"\n",
119+
"**Since everything is an object in Python programming, data types are actually classes and variables are instances(object) of these classes.**\n",
120+
"\n"
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": 4,
126+
"metadata": {},
127+
"outputs": [
128+
{
129+
"name": "stdout",
130+
"output_type": "stream",
131+
"text": [
132+
"5 is of type <class 'int'>\n",
133+
"2.0 is of type <class 'float'>\n",
134+
"(1+2j) is of type <class 'complex'>\n",
135+
"5 is Binary of type <class 'int'>\n",
136+
"105 is Octa of type <class 'int'>\n",
137+
"337 is Hexa of type <class 'int'>\n",
138+
"010\n"
139+
]
140+
}
141+
],
142+
"source": [
143+
"num1 = 5\n",
144+
"print(num1, 'is of type', type(num1))\n",
145+
"\n",
146+
"num2 = 2.0\n",
147+
"print(num2, 'is of type', type(num2))\n",
148+
"\n",
149+
"num3 = 1+2j\n",
150+
"print(num3, 'is of type', type(num3))\n",
151+
"\n",
152+
"num4 = 0b101 #Binary \n",
153+
"print(num4, 'is Binary of type', type(num4))\n",
154+
"\n",
155+
"num4 = 0o151\n",
156+
"print(num4, 'is Octa of type', type(num4))\n",
157+
"\n",
158+
"num4 = 0x151\n",
159+
"print(num4, 'is Hexa of type', type(num4))\n",
160+
"\n",
161+
"binary = 0b010\n",
162+
"print(\"{:03b}\".format(binary))"
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": null,
168+
"metadata": {},
169+
"outputs": [],
170+
"source": []
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": null,
175+
"metadata": {},
176+
"outputs": [],
177+
"source": []
178+
}
179+
],
180+
"metadata": {
181+
"kernelspec": {
182+
"display_name": "Python 3",
183+
"language": "python",
184+
"name": "python3"
185+
},
186+
"language_info": {
187+
"codemirror_mode": {
188+
"name": "ipython",
189+
"version": 3
190+
},
191+
"file_extension": ".py",
192+
"mimetype": "text/x-python",
193+
"name": "python",
194+
"nbconvert_exporter": "python",
195+
"pygments_lexer": "ipython3",
196+
"version": "3.10.4"
197+
}
198+
},
199+
"nbformat": 4,
200+
"nbformat_minor": 2
201+
}

‎basic/imgs/python_data_types.PNG

20.8 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /