Introduction to Python
Programming Fundamentals
October 15, 2025
Introduction to Python
- Creator: Guido van Rossum (1991)
- Type: Interpreted, high-level, object-oriented language.
- Why use Python?
- Works on Windows, Mac, Linux
- Simple English-like syntax
- Fewer lines of code
- Supports procedural, OOP, and functional styles
- Used in web, AI, data, and automation
Compiler vs Interpreter
Compiler | Interpreter |
---|---|
Translates entire code before running | Executes line-by-line |
Faster at runtime | Easier to debug |
Example: C, C++ | Example: Python |
Python Syntax Basics
- Python uses indentation (spaces) instead of braces { }.
- Standard: 4 spaces per block.
- Inconsistent indentation β error.
if 5 > 2:
print('Five is greater than two!')
Comments
# Single line comment
"""
Multi-line
comment
"""
Comments are ignored by the interpreter and used for clarity.
Variables
- Created automatically when a value is assigned.
- Dynamically typed (no need for type declaration).
x = 100
y = 'Python'
Rules:
- Start with letter or underscore.
- No spaces or special characters.
- Case-sensitive: age β Age.
Type casting:
x = str(3)
y = int(3)
z = float(3)
print(type(x))
Multiple Assignments & Unpacking
x, y, z = 'Red', 'Green', 'Blue'
a = b = c = 'Python'
fruits = ['apple', 'banana', 'cherry']
x, y, z = fruits
Printing Output
x, y, z = 'Python', 'is', 'awesome'
print(x, y, z)