Python Study Jam

SNAKE
BYTES

From understanding code to writing your first program.

Day 1: The Fundamentals TinkerHub CE Karunagappally
Concept 01

Programming vs Coding

Pipeline
1. Human Idea
2. Algorithm
3. Python Code
4. Execution

Programming

The entire problem-solving architecture. Designing algorithms, structuring logic, and planning solution flow.

Coding

The literal translation step. Writing instructions in specific programming language syntax for machine execution.

Syntax Readability

High-Level vs Low-Level

Comparison
Python (High-Level) 1 Line Focus
a = 5
b = 3
print(a + b)
Output: 8
  • ✓ Human readable syntax
  • ✓ Automatic memory management
  • ✓ Zero boilerplate headers
C (Low-Level) Manual Mgmt
#include <stdio.h>
int main() {
  int a = 5, b = 3;
  printf("%d", a + b);
  return 0;
}
Output: 8
  • ✗ Complex boilerplate structure
  • ✗ Manual type definitions
  • ✗ Direct hardware memory control
Interpreter Architecture

How Python Runs

CPython Pipeline
Step 01
Source Code
script.py
Step 02
Tokenizer
Break Tokens
Step 03
Parser
Build AST Tree
Step 04
Compiler
Bytecode (.pyc)
Step 05
PVM
Line-by-Line Run
CPython Standard Interpreter Written in C. Python compiles source code to intermediate bytecode before executing line-by-line via the Python Virtual Machine (PVM).
From Code to Output

Source Code Doesn't Magically Become a Result

Language Implementation
Source Code Language Implementation Execution Output

Source Code

The program written by a human.

Compiler

Translates source code into another representation, often machine code or an intermediate representation.

Interpreter / Runtime

Executes a program or its intermediate representation.

Real implementations can combine compilation and interpretation; they are not always mutually exclusive.
Compiled vs Interpreted

The Answer Is a Little More Interesting

CPython

Python is commonly called interpreted because developers usually run programs through a Python interpreter/runtime instead of compiling a native executable.

Standard CPython · Simplified
Python source (.py)
↓
Compilation
to Python bytecode ↓
Python virtual machine
Executes the bytecode

Source is commonly compiled to bytecode internally. The runtime executes that bytecode; programmers usually don't manage this themselves.

"Interpreted" does not mean "never compiled". Other Python implementations may work differently.

Conventional C Workflow

What Changes When We Run a C Program?

Toolchain
C source (.c) ↓ Compiler ↓ Native executable ↓ Operating system runs the executable ↓ Output
A conventional toolchain usually compiles and links before running.
Python, commonly via CPython
Typically run through a Python runtime
Bytecode is executed by the runtime
Quick interactive experimentation
Dynamic typing is common
C, conventional workflow
Usually compiled and linked first
Native machine code is executed
Compilation catches many errors before execution
Types are explicitly declared in ordinary C code
Compilation does not catch every bug, and both languages can be used in more varied workflows.
Quick Check

Predict Before You Reveal

3 Questions
Question 1 / 3
    Syntax Primitives

    The 5 Python Tokens

    Building Blocks
    Token 01

    Keywords

    Reserved core syntax words.

    if, else, for, def
    Token 02

    Identifiers

    User-defined variable names.

    name, count_1
    Token 03

    Literals

    Fixed raw constant values.

    5, 3.14, "Arjun"
    Token 04

    Operators

    Computation symbols.

    +, -, *, /, //, %, ==
    Token 05

    Punctuators

    Structure symbols.

    (), [], {}, :, ,
    CONCEPT 05

    Core Data Types

    TypeDescriptionExample
    intWhole numbers3, -10
    floatDecimal values3.14, 99.5
    strCharacter sequences"Arjun"
    boolTruth conditionsTrue, False
    NoneTypeAbsence of valueNone
    // Inspection Code
    print(type(3))
    print(type(3.14))
    print(type("Arjun"))
    print(type(True))
    <class 'int'>
    <class 'float'>
    <class 'str'>
    <class 'bool'>
    CONCEPT 06

    Arithmetic Operations

    Floor Division // Built-in

    Rounds result DOWN to nearest integer.

    print(3 // 2)
    Output: 1
    Ceiling Function math.ceil() Requires Import

    Rounds result UP to nearest integer.

    import math
    print(math.ceil(3 / 2))
    Output: 2
    Modulo Operator % Remainder

    Returns division remainder:

    10 % 2 → 0 (Even)  |  5 % 2 → 1 (Odd)
    CONCEPT 07

    Sequence Data Types

    Mutable

    List []

    Ordered collection.

    cart = ["apple"]
    cart.append("milk")
    Immutable

    Tuple ()

    Fixed collection.

    date = (26, 7, 2026)
    date[0] = 27 ✗
    Unique

    Set {}

    Unordered, distinct.

    s = {1, 2, 2, 1}
    print(s) → {1,2}
    Key : Value

    Dict {}

    Key-value mappings.

    usr = {"age": 20}
    print(usr["age"])
    CONCEPT 08

    String Manipulation

    Positioning: Indexing & Slicing

    NAME = "ARJUN"
    +0
    A
    -5
    +1
    r
    -4
    +2
    j
    -3
    +3
    u
    -2
    +4
    n
    -1
    name[0:2] → "Ar"
    Start 0 up to 2 (excluded)
    name[1:] → "rjun"
    Index 1 to end
    name[-1] → "n"
    Last character
    CONCEPT 09

    I/O Patterns

    Common Bug

    input() always returns STR

    num = input("Enter number: ") # '10'
    print(num + 10)
    TypeError: can only concatenate str (not "int") to str
    Correct Approach

    Explicit int() Casting

    num = int(input("Enter number: "))
    print(f"Result: {num + 10}")
    Enter number: 10
    Result: 20
    CONCEPT 10

    If-Else & Indentation

    // Indentation Block 4 Spaces
    num = int(input("Number: "))
    if num >= 0:
        print("Positive") # Indented 4 spaces
    elif num == 0:
        print("Zero")
    else:
        print("Negative")
    Indentation Error

    Python does not use curly braces {} for code blocks. Scope is strictly defined by whitespace!

    if num >= 0:
    print("positive") # - - IndentationError!
    IndentationError: expected an indented block
    DAY 1 COMPLETE

    Ready for Loops & Logic?

    "Python is simple to write, but knowing how it works under the hood is what separates coders from programmers."

    QUIZ 01

    Knowledge Check

    Question 1

    What will be the output of print(type("a"))?

    <class 'char'>
    <class 'str'>
    <class 'int'>
    QUIZ 02

    Knowledge Check

    Question 2

    Which of these is the correct way to take integer input from a user?

    num = input("Enter: ")
    num = int(input("Enter: "))
    num = input(int("Enter: "))
    QUIZ 03

    Knowledge Check

    Question 3

    What is the result of name = "Arjun"; print(name[1:4])?

    Arj
    rju
    rjun
    SUMMARY

    Day 1 Checklist

    • Explain Programming vs Coding
    • Describe how Python runs under the hood
    • Create and run code in Google Colab
    • Name all 5 token types
    • Use core data types and `type()`
    • Use arithmetic, `/`, `//`, `%`, and `math.ceil()`
    • Manipulate lists, tuples, sets, and dicts
    • Index and slice strings (positive/negative)
    • Take input, cast it, and use f-strings
    • Write `if-elif-else` with correct indentation
    Detailed notes & code Day 1 notes on Notion
    Next session (Day 2): Problem-solving mindset — breaking problems into steps, algorithm building, trial & error, and loops. Bring your Colab notebooks with today's practice done!