> For the complete documentation index, see [llms.txt](https://zmnako.gitbook.io/datascience/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zmnako.gitbook.io/datascience/python-keywords-and-identifiers.md).

# Python Keywords and Identifiers

This sections explains keywords (reserved words in Python) and identifiers (names given to variables, functions, classes, etc.).

### Python Keywords

There are 35 keywords in Python 3.8.2. The number of keywords varies based on the Python version.

* Keywords are the reserved words in Python.
* Keyword cannot be used as a variable name, function name or any other name identifiers.&#x20;
* Keywords are fundamental part of Python language, its syntax and structure.
* Keywords, similar to variable or function names, are case-sensitive.

Only three keywords has first letter as CAPITAL (`True`, `False`,[`None`](https://zmnako.gitbook.io/ds/python-data-hierarchy#singletons)), the rest is written in lower case (remember, keywords are case-sensitive)

All the keywords except `True`, `False` and `None` are in lowercase and they must be written as it is. The list of all the keywords is given below.

**Keywords in Python version 3.8.2**

|            |           |         |         |          |
| ---------- | --------- | ------- | ------- | -------- |
| `False`    | `True`    | `None`  | `and`   | `as`     |
| `assert`   | `async`   | `await` | `break` | `class`  |
| `continue` | `def`     | `del`   | `elif`  | `else`   |
| `except`   | `finally` | `for`   | `from`  | `global` |
| `if`       | `import`  | `in`    | `is`    | `lambda` |
| `nonlocal` | `not`     | `or`    | `pass`  | `raise`  |
| `return`   | `try`     | `while` | `with`  | `yield`  |

You can check the desired name against the list above easily to determine if it is a reserved keyword. This module allows a Python program to determine if a string or identifier is a keyword.

```python
import keyword
keyword.iskeyword(variable_name)
```

OUTPUT:

* Returns `True` if variable\_name is reserved keyword&#x20;
* Returns `False` if variable\_name is NOT reserved keyword

```python
True
False
```

### Python Identifiers

An identifier is a name that the user gives to any user created variables, functions, classes, decorators, generators etc.

#### Rule of thumb for identifiers nomenclature : <a href="#rules" id="rules"></a>

* There is **NO** limit on the length of an identifier name. It can be a character or 1000.
* 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 `_`.Names like `MyFunc`, `myFunc`, `my_variable_1` and `my_awesome_coding_skills`, all are valid example.
* Identifiers can start with `_`, for example; `__variable` is viable but it cannot start with number, for example; `22variable` or `22_variable` is not viable identifiers and Python throws syntax error
* Python reserved keywords cannot be used as identifiers.

{% tabs %}
{% tab title="Code" %}

```python
class = 2020
```

{% endtab %}

{% tab title="Output" %}

```python
File "<interactive input>", line 1
    class = 2020
           ^
SyntaxError: invalid syntax
```

{% endtab %}
{% endtabs %}

* We cannot use special symbols like **!**, **@**, **#**, **$**, **%** etc. in our identifier.

{% tabs %}
{% tab title="Code" %}

```python
group@ = 3
```

{% endtab %}

{% tab title="Output" %}

```python
File "<interactive input>", line 1
    group@ = 3
     ^
SyntaxError: invalid syntax
```

{% endtab %}
{% endtabs %}
