Skip to content

Commit 6676170

Browse files
committed
initla commit
1 parent df2f90e commit 6676170

12 files changed

+2034
-0
lines changed
+242
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "63966e1b-970b-407a-a2af-2b12861fe6fc",
6+
"metadata": {},
7+
"source": [
8+
"## Literals in Python \n",
9+
"#### =====================\n",
10+
"\n",
11+
"### Literals is a raw data given in a variable, In Python There are various types of literals they are as follows:\n",
12+
"\n",
13+
"1. **Number Literals**\n",
14+
"2. **String Literals**\n",
15+
"3. **Boolean Literals**\n",
16+
"4. **Special Literals**\n",
17+
"\n",
18+
"### 1: Number Literals: "
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 3,
24+
"id": "a57497fc-8659-4acb-9ca9-76f9a9ea2b16",
25+
"metadata": {},
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"10 100 200 300\n",
32+
"10.5 150.0 0.0015\n",
33+
"3.14j 3.14 0.0\n"
34+
]
35+
}
36+
],
37+
"source": [
38+
"\n",
39+
"a = 0b1010 #Binary Literals\n",
40+
"b = 100 #Decimal Literal\n",
41+
"c = 0o310 #Octal Literal \n",
42+
"d = 0x12c #hexadecimal literal \n",
43+
"\n",
44+
"# float literal \n",
45+
"float_1 = 10.5\n",
46+
"float_2 = 1.5e2\n",
47+
"float_3 = 1.5e-3\n",
48+
"\n",
49+
"#complex literal \n",
50+
"x= 3.14j\n",
51+
"\n",
52+
"print(a,b,c,d)\n",
53+
"print(float_1,float_2,float_3)\n",
54+
"print(x, x.imag, x.real)"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"id": "724e490d-296d-49c6-b514-a22d678d3bc4",
60+
"metadata": {},
61+
"source": [
62+
"### 2. String Literals"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 1,
68+
"id": "519998b4-9415-459c-a8a7-1c422d6aec00",
69+
"metadata": {},
70+
"outputs": [
71+
{
72+
"name": "stdout",
73+
"output_type": "stream",
74+
"text": [
75+
"Single-quoted string: Hello, world!\n",
76+
"Double-quoted string: Python programming\n",
77+
"Triple single-quoted string:\n",
78+
" This is a\n",
79+
"multi-line string.\n",
80+
"Triple double-quoted string:\n",
81+
" This is another\n",
82+
"multi-line string.\n",
83+
"Escaped characters: This is a newline:\n",
84+
"And this is a tab:\tHello\n",
85+
"Raw string: C:\\Users\\Name\\Folder\n",
86+
"f-string: Hello, Alice!\n",
87+
"Unicode string: 😄\n",
88+
"Byte string: b'Hello, bytes!'\n",
89+
"72\n",
90+
"101\n",
91+
"108\n",
92+
"108\n",
93+
"111\n",
94+
"44\n",
95+
"32\n",
96+
"98\n",
97+
"121\n",
98+
"116\n",
99+
"101\n",
100+
"115\n",
101+
"33\n"
102+
]
103+
}
104+
],
105+
"source": [
106+
"# Single quoted string\n",
107+
"string_1 = 'Hello, world!'\n",
108+
"\n",
109+
"# Double quoted string\n",
110+
"string_2 = \"Python programming\"\n",
111+
"\n",
112+
"# Triple single-quoted string (multiline)\n",
113+
"string_3 = '''This is a\n",
114+
"multi-line string.'''\n",
115+
"\n",
116+
"# Triple double-quoted string (multiline)\n",
117+
"string_4 = \"\"\"This is another\n",
118+
"multi-line string.\"\"\"\n",
119+
"\n",
120+
"# Escaped characters\n",
121+
"string_5 = \"This is a newline:\\nAnd this is a tab:\\tHello\"\n",
122+
"\n",
123+
"# Raw string\n",
124+
"string_6 = r\"C:\\Users\\Name\\Folder\"\n",
125+
"\n",
126+
"# f-string (formatted string literal)\n",
127+
"name = \"Alice\"\n",
128+
"string_7 = f\"Hello, {name}!\"\n",
129+
"\n",
130+
"# Unicode string (Python 2.x example)\n",
131+
"string_8 = u\"\\U0001F604\"\n",
132+
"\n",
133+
"\n",
134+
"# Defining a byte string\n",
135+
"string_9 = b\"Hello, bytes!\"\n",
136+
"\n",
137+
"\n",
138+
"# Print all the strings\n",
139+
"print(\"Single-quoted string:\", string_1)\n",
140+
"print(\"Double-quoted string:\", string_2)\n",
141+
"print(\"Triple single-quoted string:\\n\", string_3)\n",
142+
"print(\"Triple double-quoted string:\\n\", string_4)\n",
143+
"print(\"Escaped characters:\", string_5)\n",
144+
"print(\"Raw string:\", string_6)\n",
145+
"print(\"f-string:\", string_7)\n",
146+
"print(\"Unicode string:\", string_8)\n",
147+
"print(\"Byte string:\", string_9)\n",
148+
"# Iterating through a byte string\n",
149+
"for byte in string_9:\n",
150+
" print(byte) # Prints the byte values (integers representing the ASCII values)\n"
151+
]
152+
},
153+
{
154+
"cell_type": "markdown",
155+
"id": "fa39fafd-8e42-4103-aa3c-07bfae1ef3ef",
156+
"metadata": {},
157+
"source": [
158+
"### 3. Boolean Literals"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": 3,
164+
"id": "ef2ba7e6-2fab-4594-8573-f5bdf21f29e3",
165+
"metadata": {},
166+
"outputs": [
167+
{
168+
"name": "stdout",
169+
"output_type": "stream",
170+
"text": [
171+
"a 5\n",
172+
"b 10\n"
173+
]
174+
}
175+
],
176+
"source": [
177+
"a = True + 4\n",
178+
"b = False + 10\n",
179+
"\n",
180+
"print(\"a\", a)\n",
181+
"print(\"b\", b)\n"
182+
]
183+
},
184+
{
185+
"cell_type": "markdown",
186+
"id": "29077efa-3d81-42f7-934e-f4cf05294bb9",
187+
"metadata": {},
188+
"source": [
189+
"### 4. Special Literals"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": 4,
195+
"id": "8f6d3a3a-bea8-4624-b69c-0105f9b431d3",
196+
"metadata": {},
197+
"outputs": [
198+
{
199+
"name": "stdout",
200+
"output_type": "stream",
201+
"text": [
202+
"None\n"
203+
]
204+
}
205+
],
206+
"source": [
207+
"a = None \n",
208+
"print(a)\n",
209+
"\n"
210+
]
211+
},
212+
{
213+
"cell_type": "code",
214+
"execution_count": null,
215+
"id": "d06ae7ea-6c53-4afd-9df9-3b3670eb3449",
216+
"metadata": {},
217+
"outputs": [],
218+
"source": []
219+
}
220+
],
221+
"metadata": {
222+
"kernelspec": {
223+
"display_name": "Python 3 (ipykernel)",
224+
"language": "python",
225+
"name": "python3"
226+
},
227+
"language_info": {
228+
"codemirror_mode": {
229+
"name": "ipython",
230+
"version": 3
231+
},
232+
"file_extension": ".py",
233+
"mimetype": "text/x-python",
234+
"name": "python",
235+
"nbconvert_exporter": "python",
236+
"pygments_lexer": "ipython3",
237+
"version": "3.13.1"
238+
}
239+
},
240+
"nbformat": 4,
241+
"nbformat_minor": 5
242+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "cd483008-d51e-4cb7-8963-c42008b8410a",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": []
10+
}
11+
],
12+
"metadata": {
13+
"kernelspec": {
14+
"display_name": "Python 3 (ipykernel)",
15+
"language": "python",
16+
"name": "python3"
17+
},
18+
"language_info": {
19+
"codemirror_mode": {
20+
"name": "ipython",
21+
"version": 3
22+
},
23+
"file_extension": ".py",
24+
"mimetype": "text/x-python",
25+
"name": "python",
26+
"nbconvert_exporter": "python",
27+
"pygments_lexer": "ipython3",
28+
"version": "3.13.1"
29+
}
30+
},
31+
"nbformat": 4,
32+
"nbformat_minor": 5
33+
}

0 commit comments

Comments
 (0)