|
174 | 174 | " PI = 3.14159\n",
|
175 | 175 | " ```\n",
|
176 | 176 | "<br />\n",
|
| 177 | + "\n", |
177 | 178 | "8. **Global Identifiers:**\n",
|
178 | 179 | " ```python\n",
|
179 | 180 | " global_variable = 10\n",
|
|
249 | 250 | "id": "f9271fdf-38aa-410f-b258-fc325e23b8c7",
|
250 | 251 | "metadata": {},
|
251 | 252 | "source": [
|
252 |
| - "❗**Gotcha**: `isidentifier` is a bit misleading as it returns `True` for keywords which cannot be used as identifier. There is already [an issue for that](https://bugs.python.org/issue33014)." |
| 253 | + "❗**Gotcha**: `isidentifier` is a bit misleading as it returns `True` for keywords which cannot be used as identifier." |
253 | 254 | ]
|
254 | 255 | },
|
255 | 256 | {
|
|
297 | 298 | "with = 1"
|
298 | 299 | ]
|
299 | 300 | },
|
| 301 | + { |
| 302 | + "cell_type": "code", |
| 303 | + "execution_count": null, |
| 304 | + "id": "f07984dc-358c-4591-a2ef-0433ec3b91da", |
| 305 | + "metadata": {}, |
| 306 | + "outputs": [], |
| 307 | + "source": [ |
| 308 | + "from tabulate import tabulate\n", |
| 309 | + "\n", |
| 310 | + "\n", |
| 311 | + "table_data = []\n", |
| 312 | + "for possible_identifier in possible_identifiers:\n", |
| 313 | + " is_identifier = possible_identifier.isidentifier()\n", |
| 314 | + " is_keyword = possible_identifier in keyword.kwlist\n", |
| 315 | + " table_data.append([possible_identifier, is_identifier, is_keyword])\n", |
| 316 | + "\n", |
| 317 | + "headers = [\"Identifier\", \"isidentifier\", \"iskeyword\"]\n", |
| 318 | + "\n", |
| 319 | + "print(tabulate(table_data, headers=headers, tablefmt=\"grid\"))" |
| 320 | + ] |
| 321 | + }, |
300 | 322 | {
|
301 | 323 | "cell_type": "markdown",
|
302 | 324 | "id": "479277ab-15f9-4261-a932-bb8e160e702c",
|
|
349 | 371 | "execution_count": null,
|
350 | 372 | "id": "13e74c8c-fc1a-4d3e-94c8-903359591e5c",
|
351 | 373 | "metadata": {
|
| 374 | + "editable": true, |
| 375 | + "slideshow": { |
| 376 | + "slide_type": "" |
| 377 | + }, |
352 | 378 | "tags": [
|
353 | 379 | "raises-exception"
|
354 | 380 | ]
|
|
1398 | 1424 | "cell_type": "code",
|
1399 | 1425 | "execution_count": null,
|
1400 | 1426 | "id": "9843aace-0147-408a-ab0d-8643be6a0f0f",
|
1401 |
| - "metadata": {}, |
| 1427 | + "metadata": { |
| 1428 | + "editable": true, |
| 1429 | + "slideshow": { |
| 1430 | + "slide_type": "" |
| 1431 | + }, |
| 1432 | + "tags": [] |
| 1433 | + }, |
1402 | 1434 | "outputs": [],
|
1403 | 1435 | "source": [
|
1404 | 1436 | "import sys\n",
|
|
1422 | 1454 | "cell_type": "code",
|
1423 | 1455 | "execution_count": null,
|
1424 | 1456 | "id": "26f538bd-910d-442a-aece-54b3cd3c43b5",
|
1425 |
| - "metadata": {}, |
| 1457 | + "metadata": { |
| 1458 | + "editable": true, |
| 1459 | + "slideshow": { |
| 1460 | + "slide_type": "" |
| 1461 | + }, |
| 1462 | + "tags": [] |
| 1463 | + }, |
1426 | 1464 | "outputs": [],
|
1427 | 1465 | "source": [
|
1428 | 1466 | "if \"pyodide\" in sys.modules:\n",
|
|
2302 | 2340 | "cell_type": "code",
|
2303 | 2341 | "execution_count": null,
|
2304 | 2342 | "id": "ea01912c-c31d-4b67-89cf-b629b20aa8b0",
|
2305 |
| - "metadata": {}, |
| 2343 | + "metadata": { |
| 2344 | + "editable": true, |
| 2345 | + "slideshow": { |
| 2346 | + "slide_type": "" |
| 2347 | + }, |
| 2348 | + "tags": [ |
| 2349 | + "raises-exception" |
| 2350 | + ] |
| 2351 | + }, |
2306 | 2352 | "outputs": [],
|
2307 | 2353 | "source": [
|
2308 | 2354 | "dict3 = dict1 | dict2\n",
|
|
2894 | 2940 | {
|
2895 | 2941 | "cell_type": "markdown",
|
2896 | 2942 | "id": "b46061df-1039-4abc-b9c2-e048621a482b",
|
2897 |
| - "metadata": {}, |
| 2943 | + "metadata": { |
| 2944 | + "editable": true, |
| 2945 | + "slideshow": { |
| 2946 | + "slide_type": "" |
| 2947 | + }, |
| 2948 | + "tags": [] |
| 2949 | + }, |
2898 | 2950 | "source": [
|
2899 | 2951 | "\\[<< []() | [Index](./00_index.ipynb) | [Memory Management in Python](./02_memory_management_in_python.ipynb) >>\\]"
|
2900 | 2952 | ]
|
|
2917 | 2969 | "name": "python",
|
2918 | 2970 | "nbconvert_exporter": "python",
|
2919 | 2971 | "pygments_lexer": "ipython3",
|
2920 |
| - "version": "3.11.4" |
| 2972 | + "version": "3.8.18" |
2921 | 2973 | }
|
2922 | 2974 | },
|
2923 | 2975 | "nbformat": 4,
|
|
0 commit comments