What is Python (prog lang) used for?

My son is studying it in high school and I hear how widely used it is but what exactly are the real-life applications everyone is using it for? I use javascript in my websites because it seems to integrate more easily. I guess people combine Python and C++ but why not just use C++?

In other words, what would I actually use Python for?

Python is a general purpose programming language so you can use it to write almost any type of application. Much of Google as well as Youtube is written in it for example. Bank of America and Wall Street also use it as do countless other smaller players. What makes Python somewhat unique is that it is incredibly useful and powerful for real-world applications and it also makes a great teaching language because it is fairly easy to read, full featured and avoids much of the unnecessary design flaws and formality that other languages usually impose for little reason.

That last reason is the biggest one for why someone would choose to write a program in Python rather than C++. Python is simply cleaner, can usually get the same job done in less code, easier to debug and more logically consistent.

This article expands on what I said but you should be happy they are teaching your son using Python. Unlike some other teaching languages, Python has very real practical applications in the real world and there are even highly paid programmers and analysts whose work depends on it.

At my last two jobs, I was thrown some responsibility to put together a test system. After consulting some senior test engineer friends of mine, I decided to write a simple framework in python. I don’t know python, but I was able to make it happen…with a little help from Dr. Google.

It worked for me because there are so many libraries already available. Once I figured out the very basics of function calls and variable patterns, I was able to cobble together just about anything I needed.

Python is kind of a “glue” language – it interfaces well with code written in other languages and is generally more flexible that those other languages, but at a significant performance cost. A typical python project would construct the speed-critical parts of the system in a lower level language like C++, but use python to connect these components together because it is much more flexible.

One would probably not want to use a database engine that was written in python, but using python to query the database and make results available in a web framework is a pretty standard use case.

Python is used a wide variety of applications. It’s strength is a skilled programmer can write production-quality code more quickly than a lot of other languages. The reasons for that are (IMO):

a) the language is a lot more concise than a lot of other languages, but is still an easy-to-read language (most languages that value conciseness tend to be quite difficult to read)
b) the language by its design prevents several classes of bugs from even being possible, which makes it much easier for the programmer to write code
c) As mentioned by others, it has a very large, well-designed set of libraries covering common functionality
d) It has a very good interface for extending the language with new libraries written in the C language. There are times when the only real way to perform a task is in the C language. Python is one of the few higher-level language where it’s plausible to extend the standard library in this way, and that allows Python to be used in areas where other higher-level languages can’t.

The chief disadvantage of python is its performance. It doesn’t have good facilities for taking advantage of multi-core processors (yes, it can do message passing, but that remains a very unpopular technique in most applications). A python program running on the main implementation (CPython) will be about 100 times slower than equivalent C code for CPU-intensive tasks. The Java language has a reputation for being slow, but it will typically wipe the floor with Python on long-running tasks.

The thing is, though, an awful lot of computer programs aren’t performance critical. Your typical user interface is a good example. The computer is so much faster than the human that using the computer to its fullest capacity is an unnecessary waste of programmer time (computer games are a notable counter-example, and because of this, the rendering engines of games are still written in C/C++).

My brother-in-law uses Python as the installer language when he worked at a large computer company. I know others at that company who use the MatLab engine for math-intensive scientific calculations.

I’m using Python in teaching my introductory programming language, which includes both CS and non-CS majors. We do some form handling (tkinter), get to introduce lambda functions (!) and expose them to some of the great collections interfaces. It’s got some powerful features, like string splicing, which require calls to libraries in C, C++ and Java.

One great “feature” of Python is it’s named after Monty Python’s Flying Circus, so I get to play all kinds of video clips during class (“What is your favorite color” after discussing RGB colors, for example). The students are enjoying learning the language and seem to be actually LEARNING how programs work. We’re using the Zelle book, by the way.

My company’s applications are written almost entirely in Python (with Dojo for the Javascript) - it’s operational management software for large-scale industrial plants like oil refineries, LNG plants, power stations, synchrotrons and the like.

TheSquare Kilometre Arraysuper-radio-telescope will be using Python in a big way as well.

It gets used a lot in bioinformatics, seeming to have mostly replaced Perl for that use with everyone I know.

we’re using python at the moment to create a tool that reads specialised XML formats and make changes and then export the XML again. In less than a day we had the basic ability to open and parse the XML running because so much of was available in built in libraries.

You’re a math teacher, right? At what level do you teach it?

I write a lot of C++. IMHO it is a language that should have been strangled at birth. It isn’t a real OO language, and whilst it tries to do a huge range of things, it does every one of them badly.

The entire rationale for C++ was flawed from the outset, and it has never got better since.

Even Python doesn’t really work all that well with C++. Python integrates well with C, but C++'s type system (such as it is) doesn’t fit all that well, and you end up with ever more grief. Not that you can’t do it, and not that people don’t.

Many people use a restricted subset of C++, and that works OK. If you just use the additional syntax to get better controlled encapsulation, it is fine. But stay away from templates, and don’t go down the path of creating personal psuedo-languages by overuse of operator overloading. These make for impossible to maintain code.

Productivity with C++ is significantly worse, simply because it forces you to jump through idiotic hoops to get anything advanced done. The other thing to stay away from is the Boost library. An insane set of included templates that creates an almost but not quite set of additional capabilities in the most insane and impossible to debug manner. You can play a game. Take a reasonably useful program written in C++ and using Boost, and change a single character. The object of the game is to create the largest number of lines of error messages from that one change. It is trivial to get hundreds of of lines incomprehensible errors.

C++ is just a bad answer to the wrong question. It has become the default language of a lot of FOSS software, and by default Gnu/Linux. But that is more by accident than any positive attribute. If you had the choice and were writing a system from scratch you would try hard to avoid C++.

I despair of universities that have chosen it as a teaching language. Students will spend more time leaning stupid idiosyncratic rules than learning to actually program. And it never gets any better.

The Linux kernel and most of the GNU toolset are written in C, not C++.

What language would you recommend then if you are doing low level performance critical programming? eg writing a games engine?

C.

In terms of modern languages, this is the kind of thing that Rust is for. Deterministic memory control (e.g… no garbage collection), but with more modern language features through zero- or low-cost abstractions.

The language was specifically developed by Mozilla for a high-performance rendering engine, but without the possibility for the kind of memory errors that are possible in C.

This was both my experience and my wife’s experience when in school. Most of the time and mental effort were spent getting conceptually simple programs and algorithms implemented in cumbersome IDEs and bloated language syntax. What should be 1-hour homework assignments were whole-week struggles to complete.

True. What I meant was a huge part of the next layer of open source software that is layered onto the OS. There have been OSes written in C++ (Choices comes to mind) but for the most part C is indeed the base of all Unix variants.

High school and lower level college.

. . . for which purpose, of course, the text editor of choice will always be TECO.

:smiley: :eek:

This year I’ve given up on Python and gone back to Excel for test and measurement. Python is cross-platform and an OK language for writing scripts in, but Excel has a native GUI and native persistent storage, and exposes the native persistent storage in the native GUI.

This leads me to observe that a lot of Python work is done with Web interfaces, where the Web interface is “native” to the application. and where a spreadsheet would not be a suitable form of persistent storage.

I think that display and storage are underated aspects of language design.