Python Progamming/Basics of Python Language

Python Keywords and Identifiers

Updated on January 12, 2026
2 min read

Python Keywords

Python keywords are reserved words with specific functions and restrictions in the language. Currently, Python has thirty-five keywords and four soft keywords. These keywords are always available in Python, which means you don’t need to import them. Understanding how to use them correctly is fundamental for building Python programs. They cannot be used as variable names, function names, or identifiers.

Total Keywords in Python

Python has 35 keywords (in modern Python versions).

Python Keywords

S No.KeywordPurpose
1FalseBoolean false value
2NoneRepresents no value
3TrueBoolean true value
4andLogical AND operator
5asCreates alias
6assertDebugging check
7breakExits a loop
8classDefines a class
9continueSkips current loop iteration
10defDefines a function
11delDeletes an object
12elifElse if condition
13elseExecutes when if is false
14exceptHandles exceptions
15finallyRuns after try-except
16forLooping statement
17fromImports specific parts
18globalDeclares global variable
19ifConditional statement
20importImports a module
21inChecks membership
22isTests object identity
23lambdaCreates anonymous function
24nonlocalRefers to outer function variable
25notLogical NOT
26orLogical OR
27passEmpty statement
28raiseRaises exception
29returnReturns value
30tryHandles errors
31whileLooping statement
32withUsed for resource management
33yieldReturns generator value
34matchPattern matching
35caseUsed in match statements

Example

if age > 18:      # if is a keyword
    return True  # return and True are keywords

Python Identifiers

An identifier is a name that identifies a variable, function, class, module, or other object. Identifiers are fundamental for writing Python code because they allow you to refer to data and functions in your programs using descriptive names.

Rules for Identifiers

  • Must start with a letter (a–z, A–Z) or underscore (_)
  • Cannot start with a number
  • Cannot use keywords
  • No special symbols except underscore
  • Case-sensitive

Valid Identifiers

total = 10
marks = 95
_count = 5
studentName = "Alex"

Invalid Identifiers

1num = 10       # starts with number
total-marks = 90   # special character
if = 5         # keyword used

Difference Between Keywords and Identifiers

KeywordIdentifier
Reserved wordUser-defined name
Fixed meaningMeaning decided by programmer
Cannot be changedCan be changed
Example: ifExample: age
Python Keywords and Identifiers | Python Progamming | Learn Syntax