|  | 
|  | 1 | +{ | 
|  | 2 | + "cells": [ | 
|  | 3 | + { | 
|  | 4 | + "cell_type": "markdown", | 
|  | 5 | + "metadata": {}, | 
|  | 6 | + "source": [ | 
|  | 7 | + "# Python Keywords" | 
|  | 8 | + ] | 
|  | 9 | + }, | 
|  | 10 | + { | 
|  | 11 | + "cell_type": "markdown", | 
|  | 12 | + "metadata": {}, | 
|  | 13 | + "source": [ | 
|  | 14 | + "Keywords are the reserved words in python\n", | 
|  | 15 | + "\n", | 
|  | 16 | + "We can't use a keyword as variable name, function name or any other identifier\n", | 
|  | 17 | + "\n", | 
|  | 18 | + "Keywords are case sentive" | 
|  | 19 | + ] | 
|  | 20 | + }, | 
|  | 21 | + { | 
|  | 22 | + "cell_type": "code", | 
|  | 23 | + "execution_count": 2, | 
|  | 24 | + "metadata": {}, | 
|  | 25 | + "outputs": [ | 
|  | 26 | + { | 
|  | 27 | + "name": "stdout", | 
|  | 28 | + "output_type": "stream", | 
|  | 29 | + "text": [ | 
|  | 30 | + "['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']\n", | 
|  | 31 | + "('Total number of keywords ', 31)\n" | 
|  | 32 | + ] | 
|  | 33 | + } | 
|  | 34 | + ], | 
|  | 35 | + "source": [ | 
|  | 36 | + "#Get all keywords in python 3.6\n", | 
|  | 37 | + "\n", | 
|  | 38 | + "import keyword\n", | 
|  | 39 | + "\n", | 
|  | 40 | + "print(keyword.kwlist)\n", | 
|  | 41 | + "\n", | 
|  | 42 | + "print(\"Total number of keywords \", len(keyword.kwlist))" | 
|  | 43 | + ] | 
|  | 44 | + }, | 
|  | 45 | + { | 
|  | 46 | + "cell_type": "markdown", | 
|  | 47 | + "metadata": { | 
|  | 48 | + "collapsed": true | 
|  | 49 | + }, | 
|  | 50 | + "source": [ | 
|  | 51 | + "# Identifiers" | 
|  | 52 | + ] | 
|  | 53 | + }, | 
|  | 54 | + { | 
|  | 55 | + "cell_type": "markdown", | 
|  | 56 | + "metadata": {}, | 
|  | 57 | + "source": [ | 
|  | 58 | + "Identifier is the name given to entities like class, functions, variables etc. in Python. It helps differentiating one entity from another." | 
|  | 59 | + ] | 
|  | 60 | + }, | 
|  | 61 | + { | 
|  | 62 | + "cell_type": "markdown", | 
|  | 63 | + "metadata": {}, | 
|  | 64 | + "source": [ | 
|  | 65 | + "Rules for Writing Identifiers:\n", | 
|  | 66 | + "\n", | 
|  | 67 | + "1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore (_).\n", | 
|  | 68 | + "\n", | 
|  | 69 | + "2. An identifier cannot start with a digit. 1variable is invalid, but variable1 is perfectly fine.\n", | 
|  | 70 | + "\n", | 
|  | 71 | + "3. Keywords cannot be used as identifiers." | 
|  | 72 | + ] | 
|  | 73 | + }, | 
|  | 74 | + { | 
|  | 75 | + "cell_type": "code", | 
|  | 76 | + "execution_count": 3, | 
|  | 77 | + "metadata": {}, | 
|  | 78 | + "outputs": [ | 
|  | 79 | + { | 
|  | 80 | + "ename": "SyntaxError", | 
|  | 81 | + "evalue": "invalid syntax (<ipython-input-3-d0026cf49b71>, line 1)", | 
|  | 82 | + "output_type": "error", | 
|  | 83 | + "traceback": [ | 
|  | 84 | + "\u001b[0;36m File \u001b[0;32m\"<ipython-input-3-d0026cf49b71>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m global = 1\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" | 
|  | 85 | + ] | 
|  | 86 | + } | 
|  | 87 | + ], | 
|  | 88 | + "source": [ | 
|  | 89 | + "global = 1" | 
|  | 90 | + ] | 
|  | 91 | + }, | 
|  | 92 | + { | 
|  | 93 | + "cell_type": "markdown", | 
|  | 94 | + "metadata": {}, | 
|  | 95 | + "source": [ | 
|  | 96 | + " We cannot use special symbols like !, @, #, ,ドル % etc. in our identifier." | 
|  | 97 | + ] | 
|  | 98 | + }, | 
|  | 99 | + { | 
|  | 100 | + "cell_type": "code", | 
|  | 101 | + "execution_count": 5, | 
|  | 102 | + "metadata": {}, | 
|  | 103 | + "outputs": [ | 
|  | 104 | + { | 
|  | 105 | + "ename": "SyntaxError", | 
|  | 106 | + "evalue": "invalid syntax (<ipython-input-5-b512271f00c8>, line 1)", | 
|  | 107 | + "output_type": "error", | 
|  | 108 | + "traceback": [ | 
|  | 109 | + "\u001b[0;36m File \u001b[0;32m\"<ipython-input-5-b512271f00c8>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m a@ = 10 #can't use special symbols as an identifier\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" | 
|  | 110 | + ] | 
|  | 111 | + } | 
|  | 112 | + ], | 
|  | 113 | + "source": [ | 
|  | 114 | + "a@ = 10 #can't use special symbols as an identifier" | 
|  | 115 | + ] | 
|  | 116 | + } | 
|  | 117 | + ], | 
|  | 118 | + "metadata": { | 
|  | 119 | + "kernelspec": { | 
|  | 120 | + "display_name": "Python 2", | 
|  | 121 | + "language": "python", | 
|  | 122 | + "name": "python2" | 
|  | 123 | + }, | 
|  | 124 | + "language_info": { | 
|  | 125 | + "codemirror_mode": { | 
|  | 126 | + "name": "ipython", | 
|  | 127 | + "version": 2 | 
|  | 128 | + }, | 
|  | 129 | + "file_extension": ".py", | 
|  | 130 | + "mimetype": "text/x-python", | 
|  | 131 | + "name": "python", | 
|  | 132 | + "nbconvert_exporter": "python", | 
|  | 133 | + "pygments_lexer": "ipython2", | 
|  | 134 | + "version": "2.7.13" | 
|  | 135 | + } | 
|  | 136 | + }, | 
|  | 137 | + "nbformat": 4, | 
|  | 138 | + "nbformat_minor": 2 | 
|  | 139 | +} | 
0 commit comments