Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning Python coming from PHP [closed]

Tags:

python

php

People also ask

Can I learn Python after PHP?

You'd probably do better to learn Python without referring to PHP (such as with the Python tutorial, docs.python.org/tutorial). PHP is improving, but it's still well behind other languages in expressiveness and features. You don't want to get stuck using PHP idioms in Python (or Java, for that matter).

Do I need PHP if I know Python?

No. They both have their own uses, and perform some tasks better than the other. Python is better suited for many applications, but it may be more resource-efficient to use PHP for some web application target purposes.

Is it worth learning PHP in 2022?

PHP is a language that can be used to build any kind of website in 2022, starting with landing pages and simple WordPress websites, and ending with complex web platforms like that of Facebook.

Should I switch from PHP to Python?

It is a very good choice for web development and good to do OOP (although it's not a strictly OOP language). For having several friends who had to develop a few years in Python after PHP, all have told me it was quite similar and the switch was easy. It may be interesting, but I don't think you will learn much from it.


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. :-)


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:

Python:

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

PHP:

$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.

Python:

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

PHP:

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

This basic intro with PHP references is a place to start

IBM Developer Works:Python Basics for PHP Programmers