Skip to content

Commit c86ba10

Browse files
committed
added str
1 parent d80ced4 commit c86ba10

File tree

1 file changed

+116
-41
lines changed

1 file changed

+116
-41
lines changed

Sequences.ipynb

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@
453453
}
454454
},
455455
"source": [
456-
"### How do we add all elements from a list to another list?\n",
457-
"We use the extend function \n",
456+
"### How do we add all elements from one list to another list?\n",
457+
"We use the `extend` function \n",
458458
"or \n",
459-
"We add the two lists using + \n",
459+
"We add the two lists using `+` \n",
460460
"or \n",
461461
"We use list unpacking "
462462
]
@@ -938,7 +938,7 @@
938938
},
939939
{
940940
"cell_type": "code",
941-
"execution_count": 51,
941+
"execution_count": 85,
942942
"metadata": {
943943
"slideshow": {
944944
"slide_type": "fragment"
@@ -949,12 +949,12 @@
949949
"name": "stdout",
950950
"output_type": "stream",
951951
"text": [
952-
"[100, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n"
952+
"[3, 200, 1]\n"
953953
]
954954
}
955955
],
956956
"source": [
957-
"x = a[::-1]\n",
957+
"x = a[::-1] # reversing a list\n",
958958
"print(x)"
959959
]
960960
},
@@ -1249,17 +1249,16 @@
12491249
}
12501250
},
12511251
"source": [
1252-
"## set\n",
1253-
"- A list of comma separated values enclosed within curly braces.\n",
1254-
"- heterogeneous (it can have values of any type)\n",
1255-
"- mutable\n",
1256-
"- unordered\n",
1257-
"- no duplicate elements"
1252+
"## str\n",
1253+
"- list of 0 or more characters enclosed within single, double or triple quotes\n",
1254+
"- immutable\n",
1255+
"- supports +ve and -ve indexing\n",
1256+
"- supports slicing"
12581257
]
12591258
},
12601259
{
12611260
"cell_type": "code",
1262-
"execution_count": 73,
1261+
"execution_count": 86,
12631262
"metadata": {
12641263
"slideshow": {
12651264
"slide_type": "subslide"
@@ -1270,38 +1269,50 @@
12701269
"name": "stdout",
12711270
"output_type": "stream",
12721271
"text": [
1273-
"set()\n"
1272+
"My name is Diptangsu Goswami\n",
1273+
"<class 'str'>\n"
12741274
]
12751275
}
12761276
],
12771277
"source": [
1278-
"# Empty set\n",
1279-
"s = set()\n",
1280-
"print(s)"
1278+
"s = 'My name is Diptangsu Goswami'\n",
1279+
"print(s)\n",
1280+
"print(type(s))"
12811281
]
12821282
},
12831283
{
1284-
"cell_type": "code",
1285-
"execution_count": 79,
1284+
"cell_type": "markdown",
12861285
"metadata": {
12871286
"slideshow": {
12881287
"slide_type": "subslide"
12891288
}
12901289
},
1290+
"source": [
1291+
"### Length of a str object"
1292+
]
1293+
},
1294+
{
1295+
"cell_type": "code",
1296+
"execution_count": 87,
1297+
"metadata": {
1298+
"slideshow": {
1299+
"slide_type": "fragment"
1300+
}
1301+
},
12911302
"outputs": [
12921303
{
12931304
"name": "stdout",
12941305
"output_type": "stream",
12951306
"text": [
1296-
"{65, 1, 4, 7, 23}\n",
1297-
"<class 'set'>\n"
1307+
"My name is Diptangsu Goswami\n",
1308+
"Length = 28\n"
12981309
]
12991310
}
13001311
],
13011312
"source": [
1302-
"s = {23, 1, 4, 65, 7}\n",
13031313
"print(s)\n",
1304-
"print(type(s))"
1314+
"l = len(s)\n",
1315+
"print('Length =', l) "
13051316
]
13061317
},
13071318
{
@@ -1312,12 +1323,12 @@
13121323
}
13131324
},
13141325
"source": [
1315-
"### Adding elements to a set"
1326+
"### We can use extended slicing to reverse a string"
13161327
]
13171328
},
13181329
{
13191330
"cell_type": "code",
1320-
"execution_count": 78,
1331+
"execution_count": 88,
13211332
"metadata": {
13221333
"slideshow": {
13231334
"slide_type": "fragment"
@@ -1328,45 +1339,109 @@
13281339
"name": "stdout",
13291340
"output_type": "stream",
13301341
"text": [
1331-
"{32, 1, 2, 4, 10}\n",
1332-
"{32, 1, 2, 4, 100, 10}\n",
1333-
"{32, 1, 2, 4, 100, 10}\n"
1342+
"revrese\n",
1343+
"eserver\n"
13341344
]
13351345
}
13361346
],
13371347
"source": [
1338-
"s = {2, 4, 32, 1, 10}\n",
1339-
"print(s)\n",
1340-
"\n",
1341-
"s.add(100)\n",
1348+
"s = 'revrese'\n",
13421349
"print(s)\n",
1343-
"\n",
1344-
"s.add(2)\n",
1350+
"s = s[::-1]\n",
13451351
"print(s)"
13461352
]
13471353
},
13481354
{
13491355
"cell_type": "markdown",
13501356
"metadata": {
13511357
"slideshow": {
1352-
"slide_type": "skip"
1358+
"slide_type": "slide"
13531359
}
13541360
},
13551361
"source": [
1356-
"***"
1362+
"### Looping over a string"
13571363
]
13581364
},
13591365
{
1360-
"cell_type": "markdown",
1366+
"cell_type": "code",
1367+
"execution_count": 89,
13611368
"metadata": {
13621369
"slideshow": {
1363-
"slide_type": "slide"
1370+
"slide_type": "fragment"
13641371
}
13651372
},
1373+
"outputs": [],
13661374
"source": [
1367-
"## str\n",
1368-
"- list of 0 or more characters enclosed within single, double or triple quotes\n",
1369-
"- immutable"
1375+
"s = 'Loop over me'"
1376+
]
1377+
},
1378+
{
1379+
"cell_type": "code",
1380+
"execution_count": 90,
1381+
"metadata": {
1382+
"cell_style": "split",
1383+
"slideshow": {
1384+
"slide_type": "fragment"
1385+
}
1386+
},
1387+
"outputs": [
1388+
{
1389+
"name": "stdout",
1390+
"output_type": "stream",
1391+
"text": [
1392+
"L\n",
1393+
"o\n",
1394+
"o\n",
1395+
"p\n",
1396+
" \n",
1397+
"o\n",
1398+
"v\n",
1399+
"e\n",
1400+
"r\n",
1401+
" \n",
1402+
"m\n",
1403+
"e\n"
1404+
]
1405+
}
1406+
],
1407+
"source": [
1408+
"l = len(s)\n",
1409+
"for i in range(l):\n",
1410+
" print(s[i])"
1411+
]
1412+
},
1413+
{
1414+
"cell_type": "code",
1415+
"execution_count": 91,
1416+
"metadata": {
1417+
"cell_style": "split",
1418+
"slideshow": {
1419+
"slide_type": "fragment"
1420+
}
1421+
},
1422+
"outputs": [
1423+
{
1424+
"name": "stdout",
1425+
"output_type": "stream",
1426+
"text": [
1427+
"L\n",
1428+
"o\n",
1429+
"o\n",
1430+
"p\n",
1431+
" \n",
1432+
"o\n",
1433+
"v\n",
1434+
"e\n",
1435+
"r\n",
1436+
" \n",
1437+
"m\n",
1438+
"e\n"
1439+
]
1440+
}
1441+
],
1442+
"source": [
1443+
"for ch in s:\n",
1444+
" print(ch)"
13701445
]
13711446
},
13721447
{

0 commit comments

Comments
 (0)