I like Python. It's my language of choice for server-side programming for almost any application. So before giving you a list of why you would want to write Python, here are a few reasons you might not want to write your next program in Python:
Why not Python? Platform issues.¶
If your next application needs to run entirely in the web browser, you'll probably be better off writing it in Javascript or some variant. While there are efforts underway to make Python-in-the-browser a good choice, they still don't have the momentum that Javascript and friends do.
The same applies if you're going to be writing a native mobile application. In this case, you'll find more support, more documentation, and more libraries available to you if you stick with the "normal" method of mobile development.
Why not Python? You are writing an operating system or device driver.¶
Pure Python (with no C-level extensions) is not known for its speedy runtime execution. It's also a garbage-collected language with a fairly large runtime library, so if you need to have super fine-grained control over your program's resources, or you need to manipulate hardware in a very direct way, you'll probably want to stick to C.
Why not Python? You have a super-specialized application.¶
Maybe you are a statistics whiz, and all you ever need to answer are statistics problems. In that case, you'll probably be better off with R.
Maybe you're writing single-page apps that don't do a whole lot of server-side programming. Javascript may again be your best bet.
Maybe you're writing stored procedures for an Oracle Database. In this case, you're going to want to use PL/SQL.
If your application does fall into the 'super-specialized' category, there's a good chance that someone has created a specialized programming language that fills that niche precisely. That, however, brings us to our first reason you would want to use Python...
Why Python? You need to integrate across different application domains.¶
It's been said that Python's not the best language for very many hyper-specialized problem domains, but it's the second-best language for all of them. It's perfectly reasonable (and common) to write a Python program that:
- Loads data from an SQL database...
- Combines that data with other data sources and APIs on the web...
- Builds a statistical or machine learning model in memory...
- Uses the data and model to create powerful visualizations...
- And exposes it all as a REST API on the web.
Why Python? You don't like managing the fiddly bits yourself¶
Python's a memory-managed language, so you don't have to worry about all the stack overflow or wild pointer issues that you'd have to concern yourself with in C or similar languages.
Python also includes powerful built-in data types:
- Unicode
str
-ings - Unbounded-size
int
-egers - Dynamically growing/shrinking
list
s dict
-ionaries that are implemented using speedy hash tables
Sure, it can be fun developing your own data structures. But it sure is nice having pre-optimized ones available.
Why Python? It is (or at least can be) super-readable¶
Python is often described as "executable psuedocode" because of its excellent readability. Code is read more often than it's written, so keeping everything obvious is good for you in the long run.
One thing that Python gets some flak about is that it uses indentation to indicate the blog structure of code:
if this:
do_something()
elif that:
if the_other:
do_something_else(1)
else:
do_something_else(2)
else:
do_the_other_thing()
In my opinion, using indentation is a very good thing. Our brains see the indentation and infer structure from it; having the syntax of the language "see" the code in the same way helps avoid a multitude of errors.
Oh, and by the way? The code above is valid Python, so long as all the functions and variables are defined:
this = False
that = True
the_other = False
def do_something(value):
print('Do something with', value, '!')
if this:
do_something(1)
elif that:
if the_other:
do_something(2)
else:
do_something(3)
else:
do_something(4)
Why Python? Syntax consistency¶
Python tries very hard to ensure that there's one preferred syntax to express an idea. For instance, if you want to get a substring in Python, you use the 'slice' syntax:
s = 'The quick brown fox jumps over the lazy dog'
s[4:9]
If, on the other hand, you need to get a few elements from the middle of a list, you use... the 'slice' synax again:
lst = [
'zero', 'one', 'two', 'three', 'four',
'five', 'six', 'seven', 'eight', 'nine',
'ten'
]
lst[4:9]
But what about getting the length of a string versus a list? Use the len
built-in function:
len(s)
len(lst)
Why Python? It comes "with batteries included."¶
In addition to the powerful built-ins, Python's standard library comes with, to name a few modules...
- specialized collection types including deques and counters
- frameworks to build your own socket server, HTTP server, and SMTP server
- a full-fledged logging system inspired by Log4j
- a full-fledged unit testing system inspired by JUnit
- command-line parsing and automation support
- compression and archiving
- multithreading and multiprocessing support
- support for sending (SMTP), receiving (IMAP & POP), and processing (MIME) email
- ... and a whole lot more
All this comes before you start installing third-party packages, which brings us to....
Why Python? The package index PyPI.org¶
As I'm writing this, there are 217,999 third-party Python packages available on the Python package index. Some of the things you can find there, installable with a single command, include:
- multiple full-fledged web application frameworks
- data science and machine learning tools
- cloud computing automation
- image manipulation and computer vision
Why Python? It's the leading language for developing machine learning and data science applications.¶
So there is one area where Python isn't the second-best, and that's in the machine learning space. With flagship libraries such as TensorFlow, PyTorch, and SciKit-Learn primarily or only providing Python programming interfaces, Python is the language that gets the newest stuff, first.
And above, where I mentioned that Python's not the fastest? Well, that only applies to pure Python; the libraries listed above use Python extensions coded in C or Fortran to speed things up to machine-native speed. So you get developer performance and runtime performance in a single platform.
Why Python? A fantastic community that isn't going anywhere¶
Python is an incredibly welcoming and beginner-friendly community. There are dozens of regional conferences and hundreds of local user groups that meet on a regular basis to learn and share knowledge about Python and its ecosystem.
Have I convinced you?¶
Hopefully this has been enough to pique your interest at least a little. If you'd like to learn more, I'm currently developing an online course Python as a Second Language that helps developers add Python to their repertoire. Please feel free to email us at info@arborian.com if you're interested in the class.
Arborian also offers on-site and virtual customized instructor-led training. Please check out our course catalog and contact us if something seems interesting.