The 4 Common Python Programming Styles - dummies

By John Paul Mueller

Part of Beginning Programming with Python For Dummies Cheat Sheet

You might be a nonprogrammer or a developer who isn’t interested in learning some new arcane method of writing code. If so, Python is the a great language for you. Most programming languages use just one coding style, which reduces flexibility for the programmer. Python is different, though. You can use a number of coding styles with it to achieve differing effects. Among the various Python coding styles, here are the four commonly used:

  • Functional: Every statement is a kind of math equation. This style lends itself well to use in parallel processing activities. Academics and data scientists tend to use this coding style regularly. However, nothing stops you from using it even if you don’t fall into one of these groups.
  • Imperative: Computations occur as changes to program state. This style is most used for manipulating data structures. Scientists of all sorts rely on this programming style because it demonstrates processes so clearly.
  • Object-oriented: This is the style commonly used with other languages to simplify the coding environment by using objects to model the real world. Python doesn’t fully implement this coding style because it doesn’t support features like data hiding, but you can still use this approach to a significant degree. This is the style that most developers use, but other groups can use it when creating more complicated applications.
  • Procedural: Most people begin learning a language by using procedural code, where tasks proceed a step at a time. This style is most used for iteration, sequencing, selection, and modularization. It’s the simplest form of coding you can use. Nonprogrammers love this style because it’s the least complicated way to achieve smaller, experimental tasks.