Syntax

The basic rules that define correctly structured Python code.

Syntaxname = value

Syntax is the set of rules for how a program is written. A Python program is a list of instructions called statements, usually one per line.

Key facts

  • Python is case-sensitive: name and Name are different.
  • Statements normally end at the end of the line — no semicolons needed.
  • Indentation (spaces at the start of a line) is meaningful and defines blocks.

Example

Example · python
price = 10
quantity = 3
total = price * quantity
print(total)

# Output:
# 30

When to use it

  • A developer names variables with snake_case to follow PEP 8 and keep the codebase consistent.
  • A code reviewer rejects a submission because a misspelled variable name causes a silent logic bug.
  • A beginner fixes an error after learning that Python treats 'Total' and 'total' as different names.

More examples

Case-sensitive variable names

Shows that Python distinguishes names by case, so score and Score are separate variables.

Example · python
score = 95
Score = 100  # different variable
print(score)  # 95
print(Score)  # 100

Multiple statements, one per line

Illustrates the convention of one statement per line with no semicolons required.

Example · python
item = 'book'
price = 12.99
discount = 0.1
final = price * (1 - discount)
print(item, final)

# Output:
# book 11.691

snake_case naming convention

Demonstrates PEP 8 snake_case naming for variables, the standard Python style.

Example · python
first_name = 'Grace'
last_name = 'Hopper'
full_name = first_name + ' ' + last_name
print(full_name)

# Output:
# Grace Hopper

Discussion

  • Be the first to comment on this lesson.