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
Which pieces of a line are names, literals, keywords, operators, or delimiters?
Why are some words unavailable as variable names?
Which naming mistakes stop Python, and which merely make code harder to read?
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:
coursecourse_namesession2_private_notecafé
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:
2sessionscourse-namecourse namesession.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:
Start with a letter or underscore.
Continue with letters, digits, or underscores.
Do not include spaces, hyphens, dots, quotation marks, or other punctuation.
Match capitalization exactly.
Do not use a reserved keyword.
Valid syntax can still be poor naming
All these assignments are valid:
x =45thing =10this_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.
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.
A keyword is a word reserved by Python for a grammatical role. Examples include:
if else for whiledef class return importTrue False None andor 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:
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 =45print(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+4difference =8-4product =8*4quotient =8/4remainder =9%4power =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 =Truehas_time =Truecan_start = is_ready and has_timeprint(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 =-5change =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.
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:
if is a keyword.
total >= 20 is the condition expression.
: finishes the header.
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.
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*quantitytotal = price * quantity
The second follows normal style and is easier to scan.
Sometimes a space is necessary:
notready =Trueif 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 =Falseifnot ready:print("Waiting")
Token boundaries change meaning. notready and not ready are different code.
Inside an indented block, leading whitespace has a grammatical role:
ifTrue: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.
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
Change only a literal: set completed_tasks to 5.
Change only an identifier: rename target_tasks consistently.
Change only an operator: compare with > instead of >=.
Change punctuation incorrectly on purpose: remove one colon.
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=90print(max)
The code is valid and displays 90, but future calls to max(...) fail in this runtime. Prefer:
maximum_score =90print(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: