FreeCampus Python

Python’s Words and Symbols

Learn to identify Python’s keywords, identifiers, literals, operators, and delimiters, then use that vocabulary to read and repair unfamiliar lines.
python-foundations python-syntax tokens identifiers
Open in Colab
  • Level: Beginner
  • Estimated time: 2.5–3.5 hours
  • You will learn: Identify the roles of Python’s words and symbols, create valid readable names, and diagnose token-level mistakes.
  • Practice in: Google Colab, JupyterLab, or a local editor

At first, Python punctuation can look decorative. It is not. A quote can turn digits into text. One extra equals sign can turn assignment into comparison. A colon can announce a block. Parentheses can group a calculation or call a tool.

Learning the vocabulary lets you read unfamiliar code without pretending you already understand its complete behavior.

NoteQuestions you will answer
  1. Which pieces of a line are names, literals, keywords, operators, or delimiters?
  2. Why are some words unavailable as variable names?
  3. Which naming mistakes stop Python, and which merely make code harder to read?
  4. How does context change the role of a symbol?

1. Take apart one line of Python

Consider:

total_minutes = session_count * 25

Python does not see one long command. It recognizes smaller pieces:

Piece Role Meaning here
total_minutes identifier the name that will receive a value
= operator assignment
session_count identifier a name whose value will be looked up
* operator multiplication
25 literal an integer value written directly

A smallest meaningful piece recognized by Python’s tokenizer is called a token. You do not need to operate a tokenizer to read code, but the term helps us discuss the pieces precisely.

Another line has different token roles:

print("Total:", total_minutes)
Piece Role Meaning here
print identifier the name of a built-in function
( delimiter begins the call’s argument list
"Total:" literal a text value
, delimiter separates two arguments
total_minutes identifier a value to look up
) delimiter ends the argument list

Whitespace separates some tokens and helps people see the structure. It is not included in the table as an executable action.

Python first recognizes pieces, then checks whether their arrangement follows the language grammar.

flowchart LR
  A["Source text"] --> B["Tokens<br/>names, literals, symbols"]
  B --> C["Grammar<br/>valid arrangement?"]
  C -->|yes| D["Executable instruction"]
  C -->|no| E["SyntaxError"]

Label a line yourself

Copy this line and write each token in a table:

is_ready = completed_tasks >= 3

You should find:

  • two identifiers: is_ready, completed_tasks;
  • two operators: =, >=;
  • one integer literal: 3.

The underscore is part of each identifier. The two characters > and = combine into the single comparison operator >=.

2. Identifiers are names that follow spelling rules

An identifier is the grammatical form Python uses for names. These are valid identifiers:

course
course_name
session2
_private_note
café

Python permits Unicode letters, which is why café is valid. This course uses simple ASCII names in most code because they are easier to type consistently across keyboards and tools.

These are not valid identifiers:

2sessions
course-name
course name
session.minutes

Why:

  • 2sessions starts with a digit;
  • course-name is read as course - name, not one identifier;
  • the space in course name separates two identifiers;
  • the dot in session.minutes separates an object expression and an attribute name; the complete text is not one identifier.

The practical rules are:

  1. Start with a letter or underscore.
  2. Continue with letters, digits, or underscores.
  3. Do not include spaces, hyphens, dots, quotation marks, or other punctuation.
  4. Match capitalization exactly.
  5. Do not use a reserved keyword.

Valid syntax can still be poor naming

All these assignments are valid:

x = 45
thing = 10
this_is_the_number_of_minutes_remaining_after_the_break = 35

Validity only tells you Python can read the name. Readability asks whether a person can understand it.

Prefer:

session_minutes = 45
break_minutes = 10
focused_minutes = 35

Good names are specific enough to explain the role and short enough to scan.

Snake case joins multiple words

Python code normally writes variable and function names in snake case: lowercase words separated by underscores.

learner_count = 18
materials_per_learner = 4
materials_total = learner_count * materials_per_learner

learner_count is one token, not two. The underscore belongs to the identifier.

Names beginning with one or two underscores can have special conventions. Beginners should not invent such names without a reason. _temporary is legal, but temporary is clearer unless a specific convention calls for the underscore.

3. Capitalization and spelling must match exactly

Python is case-sensitive:

course = "Python Foundations"
Course = "Scientific Python"

print(course)
print(Course)

The two names have separate bindings.

This example fails at runtime:

session_minutes = 45
print(Session_minutes)

The first character differs. Python raises NameError because Session_minutes was never assigned.

Common naming mismatches include:

Assigned Read later Difference
ticket_count tickets_count singular versus plural
total_cost totalcost missing underscore
course_name course_Name capitalization
focused_minutes focus_minutes different word form

When you see NameError, copy the missing name from the error and compare it character by character with the assignments above.

Repair a naming set

Each line below intends to use a snake-case name. Rewrite it as one valid assignment:

1st_session = 25
break-time = 5
course title = "Python"
total.minutes = 30

One possible repair:

first_session = 25
break_time = 5
course_title = "Python"
total_minutes = 30

The exact words can differ. The repaired name must follow the identifier rules and communicate the intended role.

Check your understanding

4. Keywords belong to Python’s grammar

A keyword is a word reserved by Python for a grammatical role. Examples include:

if      else      for      while
def     class     return   import
True    False     None     and
or      not       in       is

You will learn the behavior connected to these words in later units. For now, recognize that you cannot use them as ordinary names.

This is invalid:

class = "Python Foundations"

Python sees class as the beginning of a class statement, not as a variable name. The rest of the line does not fit that grammar, so parsing stops.

This repair is valid and clearer:

course_class = "Python Foundations"

Keywords are not commands by themselves

Writing a keyword without the structure it requires may be invalid:

if

The word if begins a conditional statement. Python expects a condition, a colon, and an indented body. Recognizing the keyword tells you which grammatical shape to expect.

Check a word after making a prediction

Python’s standard library provides the keyword module. This example uses import and a loop before their full lessons, so read it as a guided exploration:

import keyword

print(keyword.iskeyword("for"))
print(keyword.iskeyword("total"))
print(keyword.iskeyword("return"))
print(keyword.iskeyword("course_name"))

Expected output:

True
False
True
False

keyword.iskeyword(...) answers whether a text value is currently reserved by Python.

Try "match", "case", "print", and "None". Predict each result first. print is a built-in name, not a keyword; shadowing it is legal but unwise.

5. Built-in names are available tools, not grammar

Python starts with names such as print, round, abs, min, and max available. They are built-ins. Unlike keywords, they are ordinary names and can technically be rebound:

print = 42

The assignment is valid, but the next call fails because print now refers to a number:

print("Hello")

In a notebook, restart the runtime after accidentally shadowing a built-in. In a file, rename the variable and run the file again.

Compare the categories:

Category Example Can it be a new variable name?
Keyword for No
Built-in name print Yes, but usually should not
Identifier you create course_name Yes
Literal "course_name" No; this is a text value

Quotation marks are decisive. course_name asks Python to look up a name; "course_name" creates text containing those characters.

Diagnose four different lines

course = "Python"
print(course)
print("course")
print
  • Line 1 assigns text to course.
  • Line 2 calls the built-in and displays the value bound to course: Python.
  • Line 3 displays the literal text course.
  • Line 4 is a name expression. In a notebook it may display a representation of the function object, but it does not call the function because there are no parentheses.

6. Operators tell Python what relationship to apply

Operators are tokens such as +, *, =, and >=. Some consist of more than one character.

Assignment and comparison

minutes = 45
print(minutes == 45)
print(minutes != 30)
  • = binds.
  • == asks “are these equal?”
  • != asks “are these different?”

Do not insert spaces inside a multi-character operator:

print(minutes > = 30)

Write >= as one token:

print(minutes >= 30)

Arithmetic operators

total = 8 + 4
difference = 8 - 4
product = 8 * 4
quotient = 8 / 4
remainder = 9 % 4
power = 2 ** 3

This lesson focuses on reading the symbols. Unit 2 covers numeric behavior, precision, floor division, and specialized numeric types.

Word operators

Not every operator is punctuation. Python has word operators such as and, or, not, in, and is. Because these words have grammatical roles, they are also reserved keywords.

is_ready = True
has_time = True
can_start = is_ready and has_time
print(can_start)

Boolean reasoning belongs to Units 2 and 4. Here, identify and as an operator that combines two operand expressions.

Context gives a symbol its role

The - symbol can negate one value or subtract a second value:

temperature = -5
change = 10 - 5

The first - is unary: it has one operand. The second is binary: it appears between two operands.

The * symbol means multiplication in an arithmetic expression:

area = 6 * 4

Later, you will see * used in function parameters, argument unpacking, and sequence repetition. Do not assign a universal English word to a symbol without reading its context.

Check your understanding

7. Delimiters mark boundaries and relationships

Delimiters separate, group, or enclose parts of code.

Parentheses: grouping or calling

Grouping:

total = (2 + 3) * 4

Calling:

print(total)

In the first line, the opening parenthesis follows an operator and groups an expression. In the second, it follows the name print and begins an argument list. Context tells you the role.

Commas: separating items

print("Total:", total)

The comma separates two arguments. It is not part of either value.

A missing comma can produce a confusing error or an unintended expression:

print("Total:" total)

Repair:

print("Total:", total)

Colons: announcing a body or separating parts

A colon after a header announces an indented block:

if total >= 20:
    print("Large total")

The if behavior is a preview. Read only the shape for now:

  1. if is a keyword.
  2. total >= 20 is the condition expression.
  3. : finishes the header.
  4. The indented call is the body.

Later, a colon can also separate keys from values in a dictionary or a start from a stop in a slice. The same token can have several grammatical contexts.

Dots: selecting an attribute

course_name = "python foundations"
print(course_name.title())

The dot connects the value found through course_name with the attribute name title. The following parentheses call that method. String methods receive full coverage in Unit 2; here, recognize that course_name.title is not one identifier.

Brackets and braces: enclosed structures

You will soon see:

scores = [80, 90, 75]
settings = {"theme": "dark"}

Brackets delimit a list; braces delimit a dictionary. Collections receive their own unit. For syntax reading, notice the opening delimiter, separated contents, and matching closing delimiter.

8. Whitespace can separate tokens or create blocks

These lines mean the same thing:

total=price*quantity
total = price * quantity

The second follows normal style and is easier to scan.

Sometimes a space is necessary:

notready = True
if notready:
    print("Waiting")

The code above is actually valid, but notready is one identifier. If the intention was to apply the not operator to a name ready, write:

ready = False
if not ready:
    print("Waiting")

Token boundaries change meaning. notready and not ready are different code.

Inside an indented block, leading whitespace has a grammatical role:

if True:
    print("Inside the block")

print("Outside the block")

The next lesson examines indentation in depth. Spaces around = are style; spaces at the left edge can determine block membership.

WarningDo not remove all spaces mechanically

Python can ignore some spaces, requires others to separate words, and uses leading indentation for blocks. A formatter understands these contexts; blind search-and-replace does not.

9. Annotate an unfamiliar program

Read this guided preview:

course = "Python Foundations"
completed_tasks = 3
target_tasks = 5
is_finished = completed_tasks >= target_tasks

if is_finished:
    message = "Target reached"
else:
    message = "Keep going"

print(course, message)

You do not need to master decisions yet. Annotate it using this checklist:

  1. Circle each literal.
  2. Underline every identifier.
  3. Box each keyword.
  4. Mark each operator.
  5. Pair every opening and closing parenthesis.
  6. Mark the commas and colons.
  7. Draw a vertical line along each indentation level.
Show an annotation guide
  • Literals: "Python Foundations", 3, 5, "Target reached", "Keep going".
  • Identifiers: course, completed_tasks, target_tasks, is_finished, message, print.
  • Keywords: if, else.
  • Operators: the four assignment = tokens and the comparison >=.
  • Parentheses: the pair in print(course, message).
  • Comma: separates the two arguments to print.
  • Colons: complete the if and else headers.
  • Indentation: each assignment to message belongs to the block above it.

Change one category at a time

  1. Change only a literal: set completed_tasks to 5.
  2. Change only an identifier: rename target_tasks consistently.
  3. Change only an operator: compare with > instead of >=.
  4. Change punctuation incorrectly on purpose: remove one colon.
  5. Restore the colon and explain the error message.

The output changes for different reasons. Naming the changed token category helps you explain the cause.

10. Complete a symbol-repair clinic

Each item contains one focused problem. Predict whether it is a syntax error, runtime name error, or valid-but-confusing code before revealing the repair.

A digit begins the intended name

2nd_session = 45

Repair:

second_session = 45

A keyword is used as a name

return = 30

Repair:

return_minutes = 30

A built-in is shadowed

max = 90
print(max)

The code is valid and displays 90, but future calls to max(...) fail in this runtime. Prefer:

maximum_score = 90
print(maximum_score)

A multi-character operator is split

is_ready = completed_tasks > = target_tasks

Repair:

is_ready = completed_tasks >= target_tasks

A lookup uses a string by accident

course = "Python Foundations"
print("course")

The code is valid, but it displays course. Remove the quotation marks to look up the name:

print(course)

A call is missing its closing delimiter

print("Ready"

Repair:

print("Ready")

11. Check your reading vocabulary

Key points

TipKey points
  • Python recognizes source code as tokens arranged according to grammar.
  • Identifiers begin with a letter or underscore and continue with letters, digits, or underscores.
  • Keywords are reserved; built-in names are reusable but should usually not be shadowed.
  • Literals write values directly; unquoted identifiers request name lookup.
  • Operators describe operations or relationships.
  • Delimiters group and separate parts of code.
  • A symbol’s role depends on its context.
  • Whitespace may be style, a required token separator, or block indentation.

References

Back to top