MWZ

MINDWAREZONE

beginnerPython

What are identifiers in Python?

Answer

Clear, interview-ready explanation

Identifiers are names used to identify variables, functions, classes, modules, and other objects in a Python program.

student_name = "Aman"

def calculate_total():
    pass

class Student:
    pass
            

Here, student_name, calculate_total, and Student are identifiers.

Rules for writing identifiers

  • An identifier can contain letters, digits, and underscores.
  • It cannot begin with a digit.
  • It cannot be a Python keyword.
  • It cannot contain spaces or special characters such as @, #, or -.
  • Identifiers are case-sensitive.

Valid identifiers:

user_name = "Aman"
age2 = 25
_private_value = 10
            

Invalid identifiers:

2age = 25          # Starts with a digit
user-name = "Aman" # Contains a hyphen
class = "Python"   # Uses a reserved keyword