Design News is part of the Informa Markets Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Basics of the Python Programming Environment

Adobe Stock AdobeStock_375072598_1540-800.jpeg
Python is one of the most popular languages for IoT, AI, and ML – and it pays well, too!

So, you want to learn more about Python. That’s a good decision for several reasons. First, the latest TIOBE Programming Community Index for March 2021 lists Python among the top three most popular languages. While C and Java continue to battle it out for first and second place (see Apr 2020 ratings), Python remains solidly in the third position.

Even better news comes from the annual RedMonk Ranking report in which Python outranks JAVA to become the second most popular programming language. Over the last 5 years, Python has experienced growth of around 18-19 percent. The language ranks among the most popular in several other renowned platforms also such as Stack Overflow, Github, etc.

One of the appealing aspects of Python is its applications in technologies like AI & ML. But the reasonably high salary doesn’t hurt. According to Indeed, the average Python developer salary in the US in 2021 is $110,840 per year (or $52.85 per hour). The salary amount has grown by 15% for the last 5 years.

Many places offer training in Python, including Codeacademy, Udemy, Coursera, GitHub, MIT Open Courseware, and others - just to name a few. But before learning the structure, grammar, and methodology used in Python, it's best to appreciate how the language is used in a common space, e.g, the hardware that supports much of the Internet-of-Things (IoT).

TIOBE IndexTiobe-Report-Mar2021.png

TIOBE Programming Community Index for March 2021.

Python in the IoT

One of the simplest ways to learn how Python works are by using it on a common and inexpensive hardware platform - Raspberry Pi. It helps that this platform also provides a good introduction to similar hardware environments common in the IoT space.

There are lots of different languages that can be used to program the Raspberry Pi, which is basically a Unix device. Any programs that run on Linux will run on a Raspberry Pi, such as C, C++, Java, Python, and others. A compiled language like C and C++ will work just as well as the interpreted language such as Java, Python, Pearl, and so on. But let’s stick with Python as it’s probably the most convenient.

One big reason for learning Python is that several good programming environments support it. Further, the Raspberry Pi hardware platform provides has many APIs to access its hardware pins, internal timers, and other components.

Beginners will find Python to be a straight-forward language to learn. First, Python is a high-level language, in which the details of the code have been abstracted away. For example, it is not necessary to explicitly declare data types. If a variable X is to be an integer, the programmer doesn’t have to explicitly declare it with an “int X” statement as is required in C or C++. This makes it easier to use and more time-efficient, as you don’t have to explicitly give the type of every variable used, the return values of all the variables, or the types of their arguments. The interpreter in Python handles all of those details.

Further, there are no pointers in Python, or rather, there are no pointers that the programmer can access or see. In C and C++, there are explicit pointers that allow the programmer to do pointer arithmetics. Removing pointers in Python makes it easier to do a variety of programming tasks, although it does make Python a bit less efficient than in C and C++. We’ll see why shortly.

Python is an object-oriented programming (OOP) language, which means that classes are available. For this discussion, the use of OOP will be kept to a minimum, but it is a nice feature for large programming tasks.

As a language, Python is generally a slower language when compared to C or C++. The reason is that Python is an interpreted language, not a compiled one. An interpreted language uses an interpreter to translate the instructions from the language (like Python) into machine code at runtime. In compiled languages like C and C++ which is only compiled once at run time, which translates the C or C++ code into machine code which creates an executable file. The Raspberry Pi then just runs the executable file.

In contrast, a Raspberry Pi will have to run both the Python program plus its interpreter every time the code is used. The addition of the interpret makes Python slower to run than C or C++. But it also makes Python easier for the programmer to learn and to use.

Programming Environment

There are many programming environments to use with Python. The one with the most comprehensive set of support tools is known as an integrated development environment, or IDE. Eclipse is a popular open-source IDE that supports Python and many other languages.

IDLE is the IDE that comes with Python from the Python Software Foundation website. It is part of the Python download. IDLE is a cross-platform environment that runs on Windows, Unix, and macOS. There are several ways to invoke IDLE  from Python: Menu > Programming > Python

Another way to use Python is with a text editor instead of an IDE. Simply open your favorite text editor – such as Pico or Nano, which comes with the Raspberry Pi – and begin writing code. Once the code is saved, it can be executed by typing “my test program.py” at the command line. Note that both the editor and compiler are used separately, as opposed to the integrated tool suits provided in an IDE. Both ways work fine. It just depends on the user’s preference.

Once the platform is up and going, the user is ready to write code!

John Blyler is a Design News senior editor, covering the electronics and advanced manufacturing spaces. With a BS in Engineering Physics and an MS in Electrical Engineering, he has years of hardware-software-network systems experience as an editor and engineer within the advanced manufacturing, IoT and semiconductor industries. John has co-authored books related to system engineering and electronics for IEEE, Wiley, and Elsevier.

Hide comments
account-default-image

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish