Menu
CoddyTech
Course

Python for PHP Developers

Move from PHP to Python through array and object semantics, truth tests, functions, closures, modules, and classes. Practice with multi-file tasks and build a four-step order processor.

PHP and Python side by side

The same program in PHP and in Python, from the lessons of this course.

  1. Echo, Strings, and print

    PHP files enter code with <?php and typically end statements with semicolons. Python files need neither. PHP echo adds no separator or newline; Python print separates arguments with a space and appends a newline. PHP interpolates variables in double-quoted…

    PHP
    1<?php2$name = 'Ada';3echo "Hi $name", "!", "\n";
    Python
    1name = "Ada"2print(f"Hi {name}", "!")
  2. Null, None, and Missing Keys

    Python spells absence None and booleans True and False. Test absence with is None. PHP isset returns false for both a missing key and a key holding null; array_key_exists can distinguish them. In Python, use key in data for key presence and then inspect its…

    PHP
    1<?php2$data = ['seats' => null];3echo isset($data['seats']) ? 'yes' : 'no', "\n";4echo array_key_exists('seats', $data) ? 'yes' : 'no', "\n";
    Python
    1data = {"seats": None}2print(data["seats"] is None)3print("seats" in data)
  3. PHP Arrays and Python Lists

    A PHP array is an ordered map that can mix integer and string keys. Python separates indexed sequences (list) from mappings (dict). A Python list uses contiguous zero-based positions, and a negative index counts from the end. Slices exclude their stop…

    PHP
    1<?php2$items = [4, 8];3echo array_push($items, 12), "\n";4echo $items[2], "\n";
    Python
    1items = [4, 8]2print(items.append(12))3print(items[-1])
  4. Foreach and range

    PHP foreach can bind an element by reference with &. Python for loops bind a local name to each element; rebinding that name does not replace a list slot. Mutating a mutable element is different from rebinding the loop name. Python range(start, stop) excludes…

    PHP
    1<?php2$values = [2, 4];3foreach ($values as &$value) { $value += 1; }4unset($value);5echo implode(' ', $values), "\n";
    Python
    1values = [2, 4]2for value in values:3    value += 14print(*values)
  5. Functions and Mutable Inputs

    Python defines functions with def and returns values with return. Falling off the end returns None, comparable to PHP's implicit null result. PHP array parameters normally have value semantics unless declared by reference. Python parameters are local names…

    PHP
    1<?php2function addItem($items) { $items[] = 9; }3$items = [1];4addItem($items);5echo count($items), "\n";
    Python
    1def add_item(items):2    items.append(9)3items = [1]4add_item(items)5print(len(items))
  6. CLI Input and Exact Output

    PHP CLI code often reads with fgets(STDIN), which retains the line ending; Python input() removes its trailing newline and returns text. Neither converts numeric input automatically. Python strip() removes surrounding whitespace but preserves internal spaces.…

    PHP
    1<?php2$label = trim(' Green tea ');3$cents = 305;4printf("%s: %.2f\n", $label, $cents / 100);
    Python
    1label = " Green tea ".strip()2cents = 3053print(f"{label}: {cents / 100:.2f}")

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Apply Your PHP Experience

2 lessons

More courses for PHP developers

Learn Python from another language

Frequently asked questions

Who is Python for PHP Developers for?

For people who already write PHP and want to learn Python. Each lesson starts from PHP you know and shows how Python does the same thing, so you skip the beginner basics.

Do I need to know Python already?

No. The course starts with your first Python program. You need PHP basics: variables, conditions, loops, functions and collections.

How many lessons does Python for PHP Developers have?

Python for PHP Developers contains 48 interactive lessons you can complete at your own pace.

What does Python for PHP Developers cover?

The course is organized into chapters covering: From PHP to Python, Values and Decisions, Arrays and Python Collections, Iteration and Transformations, and more.

Is Python for PHP Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Python for PHP Developers for free

Get started