Python 1 Unit 1 Lesson 1: Fundamental Terms and Definitions

PCEP 1.1: Compilation vs. Interpretation
Monday, August 12, 2024

Welcome to Python Programming!

Agenda:

  • Introductions
  • Syllabus
  • Rules & procedures
  • Brief tour of Canvas course
  • Brief tour of course website
  • Lecture

Introductions

  • What do you go by
  • Hobbies
  • Familiarity w/computers
  • Familiarity w/programming

Syllabus

Rules & Procedures

Canvas course tour

Course website tour

To submit today (in Canvas):

Course Goal:

  • Master Python fundamentals
  • Earn PCEP-30-02 certification

Python Essentials Course

https://edube.org/study/pe1

  • Create an account using your personal email address (CMS email will block verification emails)
  • Please enter your name accurately, e.g. uppercase first letters
  • You will need to provide me this email address because I will be using this same account to assign your exam vouchers and track your progress in the course.
  • This is the name that will be on your certificate

Today's PCEP Objective:

PCEP 1.1 - Understand fundamental terms and definitions

  • interpreting and the interpreter, compilation and the compiler
  • lexis, syntax, and semantics

There are many ways to run Python

  • IDLE
  • .py files
  • Shell
  • Online (onlineGDB, REPL, and many others)
  • Jupyter Notebooks
    • locally
    • in-browser with Jupyter Lite
  • CodeHS

Jupyter Lite

Lecture: terms and definitions

What is Programming?

Programming = Writing instructions for computers to follow

Algorithm = Step-by-step solution to a problem

Program = Algorithm written in a programming language

Example Algorithm: Making a peanut butter sandwich

  1. Get two slices of bread
  2. Open peanut butter jar
  3. Spread peanut butter on one slice
  4. Put slices together

Why Do We Need Programming Languages?

The Problem: Computers only understand machine code (0s and 1s)

Machine Code Example:

10110000 01100001
10110000 01100010

Human-Readable Code:

print("Hello, World!")

Programming languages bridge the gap between human thinking and computer execution.

Two Ways to Execute Programs

Compilation Process

Source CodeCompilerExecutable FileComputer Runs It

  • Translator converts entire program at once
  • Creates standalone executable file
  • Fast execution, but compilation takes time
  • Examples: C, C++, Rust

Compilation Example

Source Code (hello.c):

#include <stdio.h>
int main() {
    printf("Hello, World!");
    return 0;
}

Compilation Command:

gcc hello.c -o hello.exe

Result: hello.exe file that runs independently

Interpretation Process

Source CodeInterpreterDirect Execution

  • Translator reads and executes code line by line
  • No separate executable file created
  • Slower execution, but immediate feedback
  • Examples: Python, JavaScript, Ruby

Interpretation Example

Source Code (hello.py):

print("Hello, World!")

Execution Command:

python hello.py

Result: Code runs immediately through interpreter

Python: An Interpreted Language

Python Interpreter:

  • Reads your .py files
  • Converts Python code to bytecode
  • Executes bytecode on Python Virtual Machine

Benefits:

  • Interactive development
  • Cross-platform compatibility
  • Immediate feedback and testing

PCEP Key Terms: Lexis, Syntax, and Semantics

Lexis (Vocabulary)

The basic building blocks of the language

Python Lexical Elements:

  • Keywords: if, else, for, while, def
  • Identifiers: variable and function names
  • Literals: 42, "hello", True
  • Operators: +, -, ==, and

Syntax vs Semantics

Syntax (Grammar Rules)

How code must be written to be valid

Valid Python Syntax:

if x > 5:
    print("x is greater than 5")

Invalid Python Syntax:

if x > 5
    print("x is greater than 5")  # Missing colon

Semantics (Meaning)

Semantics

What the code actually does when executed

Syntactically correct but semantically wrong:

radius = -5
area = 3.14159 * radius * radius

The syntax is perfect, but negative radius doesn't make sense!

Python's Philosophy

The Zen of Python

import this

Key principles:

  • Beautiful is better than ugly
  • Explicit is better than implicit
  • Simple is better than complex
  • Readability counts

Python prioritizes human readability over machine efficiency

Programming Language Types

High-Level vs Low-Level

High-Level (Python, Java, JavaScript):

  • Human-friendly syntax
  • Abstract away hardware details
  • Faster development

Low-Level (Assembly, C):

  • Closer to machine code
  • More control over hardware
  • Faster execution

PCEP Practice Question

Which statement about Python is correct?

A) Python is a compiled language that creates .exe files
B) Python is an interpreted language that executes code line by line
C) Python code runs faster than compiled languages
D) Python requires compilation before execution

Today's Lab Preview

What we'll do:

  • Demonstrate compilation vs interpretation with examples
  • Explore Python interpreter in interactive mode
  • Identify lexical elements in Python code
  • Practice fundamental terminology

Goal: Master PCEP 1.1 concepts through hands-on experience

Key Takeaways

  • Programming = Writing instructions for computers
  • Compilation = Translate entire program, then execute
  • Interpretation = Translate and execute line by line
  • Python = Interpreted, high-level, human-readable
  • Lexis = Vocabulary, Syntax = Grammar, Semantics = Meaning

Ready for hands-on practice!

Next Lesson Preview

Tomorrow: PCEP 1.1 continued - Lexis, Syntax, and Semantics

  • Deep dive into Python's vocabulary
  • Syntax rules and error identification
  • Semantic meaning and logical errors

testing html comments

**Answer**: B - Python is an interpreted language