Notes: Fundamentals of Programming - Python Overview
Programming Terminology
- Program - set of coded instructions for the computer.
- Compiler - translates source code into another language (machine code).
- Low-Level Language - close to machine code (harder for humans, faster for computers).
- Syntax - rules that define valid statements in a programming language.
- Looping - repeating a set of instructions until a condition is met.
- Array - data structure holding multiple values, accessed by index.
- Pseudocode – informal description of algorithm (human-readable).
- Programming - process of designing and writing programs.
- Programmer - person who develops and tests computer programs.
- Algorithm - step-by-step procedure to solve a problem, clear and finite.
- Flowchart - diagram showing logical sequence of steps.
Goals of Programming
- 1. Make sure the program solves the intended problem.
- 2. Ensure that people can use the program easily.
- 3. Code should be easy to maintain, fix, and improve.
Problem Solving in Programming
- Process: Problem → Human instructions → Programming Language → Binary Code → Solution
- Algorithm = Step-by-step written solution.
- Flowchart = Visual diagram of steps.
- Cycle: Analysis → Design → Coding → Testing/Debugging → Execution → Back to previous step if needed.
Python Overview
- High-level language: Easy to read and write.
- General-purpose: Used in many fields (web, AI, games, CAD, data science).
- Interpreted: Runs directly, no compilation needed.
- Object-Oriented: Supports classes and objects.
- Fast Development: Edit → Run → Debug cycle is quick.
History of Python
- 1989 - Created by Guido van Rossum at CWI, Netherlands.
- 1991 - First release (v0.9.0).
- 1994 - Python 1.0 (added lambda, map, filter, reduce).
- Python 2.0 - Added list comprehensions, garbage collection.
- 2008 - Python 3.0 (Py3K) released; fixed flaws, broke backward compatibility.
- Influenced by ABC language and Modula-3.
Python Versions
- Python2.x - Legacy version ("classic" Python).
- Python3.x - Modern version, fixes flaws, widely used today.
Python Features
- Free & Open Source
- Object-Oriented
- Easy to learn & beginner-friendly
- Cross-platform (Windows, Linux, Mac, Unix)
- Can integrate with C, C++, Java, etc.
Compiler vs Interpreter
- Feature: Compiler → Translates the whole program at once; Speed: Faster execution; Memory: Needs more memory (creates object code); Debugging: Errors shown after scanning all code.
- Feature: Interpreter → Translates line by line; Speed: Slower execution; Memory: More memory efficient; Debugging: Stops immediately at first error.
Python Implementations
- CPython - default, written in C.
- Jython - runs on Java Virtual Machine.
- IronPython - runs on .NET.
- PyPy - fast, with JIT compiler.
- Stackless Python - supports micro-threads.
- MicroPython - for microcontrollers.
- Anaconda - scientific computing, data science.
Applications of Python
- Web Development
- GUI (Desktop Apps)
- Games & Graphics
- Data Science, Machine Learning, AI
- Networking & IoT (Internet of Things)
- Automation & DevOps
- Scientific Computing
- Embedded Systems
- Education & CAD
Python Syntax
Modes of Programming
- 1. Interactive Mode - Quick testing (Python Shell).
- 2. Script Mode - Writing full programs saved as .py file.
Differences
- Interactive → instant results, best for testing small code.
- Script mode → best for longer projects, easier to maintain.
Identifiers & Naming Rules
- Identifiers names for variables, classes, functions.
- Must start with letter/underscore.
- Case-sensitive (Car #car).
- No symbols like $, @, %.
- Reserved words (keywords) cannot be used.
Class Naming Rules
- Class names → start with uppercase.
- Single underscore (_var) → private.
- Double underscore ( __ var) → strongly private.
- Double underscore start & end ( init ) → special method.
Keywords
- Reserved words (cannot be used as identifiers):
- and, as, assert, break, class, continue, def,
- del, elif, else, except, finally, for, from,
- global, if, import, in, is, lambda, not, or,
- pass, print, raise, return, try, while, with,
- yield
Other Syntax Rules
- Indentation - defines code blocks (no braces {}).
- Multi-line Statements - use a backslash for continuation.
- Strings - can use quotes.
- Comments - start with #.