Learning Python coming from PHP


My dynamic language experience is solely PHP. I want to learn Python now to broaden my career opportunities and just because I like programming. 🙂

When learning Java, I used a site (lost the URL/real name now), something like “Java for PHP developers” that had all on one side of the page the PHP code, and on the other side the Java code to do the same thing. Is there a website like that for Python?

Any other recommendations/advice?


Asked By: Amy B



I’m not sure such a thing exists but Python is generally an easy language to learn. Python documentation is generally very clear and easy to follow. From the Python interpreter you can also use the dir() and help() methods to view methods, attributes and documentation which makes it easy to explore what options are available to you in Python.

A few examples of differences between PHP and Python:


x = [1, 2, 3, 4, 5]
for a in x:
    print a
print "Loop is over"


$x = array(1, 2, 3, 4, 5);
foreach($x as $a) {
    echo $a.PHP_EOL
echo 'Loop is over'.PHP_EOL;

As you can see, Python does away with using ‘{‘ and ‘}’ and instead uses indentation to see when the for-loop is complete.


x = {'spam':'hello', 'eggs':'world'}
if x.get('spam'):
    print x['spam']


$x = array('hello'=>'spam', 'world'=>'eggs');
if array_key_exists('hello', $x) {
    echo $x['hello'].PHP_EOL;
Answered By: thetaiko

The OP’s question is simple enough, but as @Pekka mentioned (or hijacked), this could be a much deeper question (requiring a more substantial answer). Yes, Python’s syntax is easy enough to learn without a book, but like any other language, it still takes quite a bit of time to master.

The suggest of Dive Into Python is valid, although the Python 3 version is only for newbies with no baggage (meaning no existing Python code, no libraries/dependencies that haven’t been ported to Python 3 yet, etc.). Sadly Mark has removed most of his online content. Here is one archive of his Python 3 book: http://www.diveintopython3.net … it is a very good high-level introduction to the language by immersing you into coding bits right away.

If you are looking for something slightly more comprehensive, I wrote Core Python Programming specifically targeted towards programmers already literate in another high-level language like Java, C/C++, PHP, Ruby, etc., who need to learn Python as quickly and as in-depth as possible… it’s more like a “deep dive” than a “quick dive.” For pure reference books that you can pull off the shelf as necessary, I would suggest either Beazley’s Python Essential Reference or Martelli’s Python in a Nutshell… both are excellent, altho Alex’s book is not rev’d to the latest Python releases yet. I’m sure he’s working on it tho. 😉

[UPDATED Jun 2015] Back on hijacked topic, there are several options when it comes to developing web apps on Python, the most popular currently is Django. That is a full-stack web framework that is the closest thing that Python has to Ruby on Rails. It has templating, an ORM, can run on various core components (RDBMSs, webservers, JavaScript libraries, etc.), comes with an amazing admin interface, and a whole lot more. For even more functionality, also take a look at Pinax. An alternative to Django is Pyramid. Instead of a single monolithic framework, Pyramid/Pylons act more like glue, tying together best-of-breed components, i.e., Jinja2 for templating, SQLAlchemy for the ORM, MochiKit as the JS library, etc. The 3rd option, primarily for high-trafficked, low-latency, scalable apps is Google App Engine. You write your apps in Python (or Java, PHP, or Go) and upload to Google to run your app on their infrastructure. Most of the development will be similar to developing web apps on a standard LAMP stack, except for the datastore. Based on Google’s BigTable, it’s a non-relational distributed object database, so the largest hurdle is overcoming thinking in a relational DB way; also released independently as Google Cloud Datastore. There’s also a relational MySQL-compatible alternative called Google Cloud SQL should you prefer that instead of a NoSQL solution. BigTable is also available as a standalone technology from App Engine and available as Google Cloud Bigtable. That enough options for you?!? 🙂

Hope this helps!

ps. If you’re looking for an upcoming comprehensive 3-day course in Python, talk to me. 🙂

Answered By: wescpy

This basic intro with PHP references is a place to start

IBM Developer Works:Python Basics for PHP Programmers

Answered By: Manquer
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.