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

# Keywords and Identifiers

## Python Keywords  <a href="#key" id="key"></a>

Keywords in Python are predefined reserved words that have specific meanings and purposes. These words cannot be used as variable or function names because they have a special meaning in the Python language.

\
&#x20;                                    **Python Keywords List** &#x20;

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

It is important to remember that these keywords have a specific meaning in Python and cannot be used as variable or function names.

\
Python Identifiers
------------------

In Python, an identifier is a name given to a variable, function, class, module or other object. An identifier can be made up of letters, digits, and underscores (\_), and must begin with either a letter or an underscore. Identifiers are case-sensitive, which means that `my_variable` and `My_Variable` are different identifiers.

Here are some examples of valid identifiers in Python:

```
x
my_var
My_Var
myVar
my_var_1
_my_var
```

And here are some examples of invalid identifiers:

```css
2myvar (starts with a digit)
my-var (contains a hyphen)
my var (contains a space)
my@var (contains a special character)
```

It's important to choose meaningful and descriptive names for your identifiers, to make your code more readable and understandable.&#x20;

### Rules for Naming an Identifier  <a href="#rules" id="rules"></a>

1. The first character of an identifier must be a letter or an underscore (\_).
2. The rest of the identifier can contain letters, digits, and underscores.
3. Identifiers are case-sensitive, which means that `my_variable` and `My_Variable` are different identifiers.
4. Python keywords cannot be used as identifiers.
5. Identifiers should be descriptive and meaningful, to make your code more readable and understandable.
6. Identifiers cannot start with a digit.&#x20;

Following these rules will help ensure that your identifiers are valid and easy to understand.&#x20;

### Some Valid and Invalid Identifiers in Python&#x20;

**Valid Identifiers:**

* my\_variable
* MY\_VARIABLE
* \_my\_variable
* my\_variable\_1
* myVariable
* var\_1

***Invalid Identifiers:***

* 1\_variable (starts with a digit)
* my-variable (contains a dash, which is not allowed)
* import (a Python keyword)
* break (a Python keyword)
* while (a Python keyword)
* my variable (contains a space, which is not allowed)

It's important to follow the rules for naming identifiers in Python to avoid errors in your code.

<br>

<br>

<br>
