MyInternships.in

Python Basics

Python Keywords and Identifiers

Keywords are reserved words with special meaning in Python, while identifiers are the names you choose for variables, functions and more.


What are Keywords?

Keywords are words that Python has reserved for its own syntax, such as if, else, for, while, def, class, and True. Because they already have a fixed meaning, you cannot use them as variable names.

Viewing all Python keywords
Python
import keyword
print(keyword.kwlist)

Common Python Keywords

KeywordPurpose
if / elif / elseConditional statements
for / whileLoops
defDefining a function
classDefining a class
returnReturning a value from a function
True / False / NoneSpecial built-in values
importBringing in a module
and / or / notLogical operators

What are Identifiers?

An identifier is the name you give to a variable, function, class, or module. Choosing clear identifiers makes your code much easier to read and maintain.

Rules for Valid Identifiers

  • Must start with a letter (a-z, A-Z) or an underscore _
  • Can contain letters, digits and underscores after the first character
  • Cannot start with a digit
  • Cannot contain spaces or symbols like -, @, or %
  • Cannot be the same as a reserved keyword
  • Are case-sensitive, so total and Total are different names
Valid vs invalid identifiers
Python
# Valid identifiers
student_name = "Meera"
_score = 90
total2 = 100

# Invalid identifiers (would cause errors)
# 2total = 100      -> starts with a digit
# student-name = "" -> contains a hyphen
# class = "A"       -> class is a reserved keyword
💡

Pick descriptive identifier names like total_marks instead of short, unclear ones like tm — your future self will thank you.

Related Python Topics

Keep learning with these closely related lessons.

Ready to use your Python skills?

Find Python, data science and software internships and fresher jobs across India.

Browse Python Internships