Career upgrade: Learn practical AI skills for better jobs and higher pay.
Level up

1.2 Identifiers, Keywords, Comments, and Basic Program Structure

Key Takeaways

  • Python identifiers can contain letters, digits, and underscores, but they cannot start with a digit.
  • Identifiers are case-sensitive, so `total`, `Total`, and `TOTAL` are three different names.
  • Keywords such as `if`, `while`, `def`, `return`, `True`, `False`, and `None` are reserved and cannot be ordinary identifiers.
  • A hash mark starts a comment outside strings, while a docstring is a string literal used as documentation.
  • Python scripts usually run from top to bottom, so a name must be defined before the executing code tries to use it.
Last updated: May 2026

Identifiers name objects

An identifier is a name used for a variable, function, parameter, class, module, or other program element. Python identifiers may contain letters, digits, and underscores. They cannot start with a digit, and they are case-sensitive.

student_count = 18
Student_count = 19
_private_note = 'draft'

The first two names are different because s and S are different characters to Python. This matters on PCEP because a snippet may assign score and later print Score, which is a different name and can raise NameError.

Candidate nameValid?Reason
total_2YesStarts with a letter and uses allowed characters
_readyYesA leading underscore is allowed
2_totalNoStarts with a digit
unit-priceNoHyphen is parsed as minus
classNoReserved keyword

Keywords are reserved

A keyword has a fixed role in the Python language. Examples include if, elif, else, for, while, break, continue, def, return, try, except, True, False, and None. You cannot use these as ordinary variable names.

Keywords make code readable to the interpreter. When Python sees if, it expects a conditional statement, not a custom variable chosen by the programmer. If a PCEP option suggests assigning to a keyword, eliminate it.

Comments and docstrings

A comment begins with # and continues to the end of the physical line, unless the hash character appears inside a string. Comments are ignored by Python execution but are important for human readers.

# Convert minutes into full hours.
hours = total_minutes // 60
label = 'room #4'

The first line is a comment. The # in 'room #4' is part of a string literal, not a comment marker.

A docstring is different. It is a string literal placed at the start of a module, function, class, or method to document that object. It is not a comment because Python creates the string value and may store it as documentation.

Basic program structure

Small PCEP snippets often run as simple scripts from top to bottom. Assignment creates or rebinds a name. A function definition creates a function object, but the function body does not run until the function is called.

def double(n):
    return n * 2

value = double(5)
print(value)

Python first defines double, then calls it, then prints 10. If the call came before the def statement executed, the name would not yet exist.

Larger programs commonly organize imports first, then constants, helper functions, and the main script actions. PCEP does not require a full application architecture, but it does expect you to know that order of execution matters.

Exam reading checklist

Use this checklist on name-focused questions:

  • Does the identifier start with a letter or underscore?
  • Does it avoid reserved keywords?
  • Is the capitalization exactly the same everywhere?
  • Has the name been assigned or defined before execution reaches it?
  • Is a # starting a real comment or appearing inside a string?

These rules are small, but they are the foundation for every later topic.

Test Your Knowledge

Which identifier is valid in Python?

A
B
C
D
Test Your Knowledge

What happens if executing code tries to read Score after assigning only score = 9?

A
B
C
D
Test Your Knowledge

In the line label = 'room #4', what is the # character?

A
B
C
D