Objective. Students write Python 3 scripts that use correct syntax, all primitive data types (int, float, str, bool, NoneType), and arithmetic, comparison, logical, and bitwise operators, aligning with PCEP exam objective PE1 (Basics of Computer Programming and Python)
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
Python is one of the most widely used programming languages in web development, automation, and data work. The PCEP (Certified Entry-Level Python Programmer) exam, issued by the Python Institute, validates that you understand Python 3 fundamentals. This lesson covers the core building blocks tested in PCEP exam objective PE1: basic computer programming concepts and Python essentials.
---
Python uses indentation to define blocks of code instead of curly braces. This is not optional — incorrect indentation causes an `IndentationError` and your script will not run. Use four spaces per level; do not mix tabs and spaces.
A Python script is a plain-text file saved with the `.py` extension. You can run it from the terminal with `python3 script.py`, or execute statements one at a time in the REPL (Read-Evaluate-Print Loop) by typing `python3` at the command line.
Comments begin with `#`. Python ignores everything after `#` on that line. Use comments to explain your intent.
```python
print("Hello, world!") # inline comment
```
---
A variable is a named storage location for a value. In Python you create one with a simple assignment:
```python
temperature = 98.6
city = "Chicago"
is_online = True
```
Naming rules (these are enforced by the language):
Convention (not enforced, but expected in professional code): use snake_case for variable names (`miles_per_hour`, not `MilesPerHour`).
---
Python has five primitive types you must know for PCEP:
| Type | Example | Notes |
|------|---------|-------|
| `int` | `42`, `-7` | Whole numbers, no size limit in Python 3 |
| `float` | `3.14`, `-0.5` | Decimal numbers, stored in IEEE 754 double precision |
| `str` | `"hello"`, `'world'` | Text, enclosed in single or double quotes |
| `bool` | `True`, `False` | Must be capitalized; subclass of `int` (`True == 1`, `False == 0`) |
| `NoneType` | `None` | Represents the absence of a value |
Use `type()` to check a value's type: `type(3.14)` returns `<class 'float'>`.
Type casting converts one type to another:
---
Arithmetic operators perform math:
| Operator | Meaning | Example | Result |
|----------|---------|---------|--------|
| `+` | Addition | `7 + 3` | `10` |
| `-` | Subtraction | `7 - 3` | `4` |
| `` | Multiplication | `7 3` | `21` |
| `/` | True division | `7 / 2` | `3.5` |
| `//` | Integer (floor) division | `7 // 2` | `3` |
| `%` | Modulo (remainder) | `7 % 2` | `1` |
| `` | Exponentiation | `2 8` | `256` |
Note: `` applied to a string repeats it: `"ab" 3` gives `"ababab"`.
Comparison operators return a `bool`:
`==`, `!=`, `<`, `>`, `<=`, `>=`
Logical operators combine boolean expressions:
Python uses short-circuit evaluation: with `and`, if the left side is False, the right side is never evaluated; with `or`, if the left side is True, the right side is skipped.
Bitwise operators work on integer bits:
`&` (AND), `|` (OR), `^` (XOR), `~` (NOT), `<<` (left shift), `>>` (right shift).
Operator precedence (highest to lowest, simplified): `**` → unary `~`, `+`, `-` → `*`, `/`, `//`, `%` → `+`, `-` → shifts → `&` → `^` → `|` → comparisons → `not` → `and` → `or`. When in doubt, use parentheses.
---
F-strings let you embed expressions inside string literals:
```python
name = "Alex"
score = 95
print(f"Student {name} scored {score} points.")
```
You can control decimal places: `f"{value:.2f}"` rounds to two decimal places.
---
While Python development does not involve physical hazards such as electrical work, professional responsibility still applies:
---
PECAP exam objective PE1 covers computer programming basics, Python's role as an interpreted language, literals, variables, operators, and basic I/O. Every concept in this lesson maps directly to PE1. When you sit the PCEP exam, expect questions that ask you to predict the output of short code snippets — exactly the skill you practice in today's REPL drill.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.