DEV Community

hebaShakeel
hebaShakeel

Posted on

Keywords and Identifiers in Python

Keywords

Python is a case sensitive programming language.

A keyword is a word that is reserved by a program because the word has a special meaning. Keywords can be commands or parameters. Every programming language has a set of keywords that cannot be used a variable name.

Python has 33 keywords:

import keyword
print(keyword.kwlist)

This prints all the keywords in Python.

Identifiers

A Python identifier is a name used to identify a variable, function, class, module or other object.

Rules for setting identifiers:

  • can only start with an alphabet or _

name = "Heba"
_name = "Heba"
1name = "Heba" ---Invalid
name1 = "Heba"

  • Followed by 0 or more letter, _ and digits

first_name = "Heba"
first-name = "Heba" ---Invalid

  • Keywords cannot be used as identifiers

Top comments (0)