PYTHON

Photo of author

By Jackson Taylor

Home » Examples » Open Cv » PYTHON

As an Amazon Associate we earn from qualifying purchases.

Python is a general-purpose programming language known for code that is easy to read and quick to write. It is free, open source and runs on Windows, macOS and Linux. That is why it is a common first language for beginners, and why professionals also use it for web development, data analysis, automation and electronics projects.

This page explains what Python is, what you can build with it, how to set it up, and what to learn first.

What is Python?

Python was created by Guido van Rossum and first released in 1991. It is an interpreted language, which means you can run your code directly without a separate compile step. It is also dynamically typed, so you do not have to declare the type of every variable in advance.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

Python also uses indentation, the spaces at the start of a line, to mark blocks of code. Many other languages use curly braces for this. The rule forces tidy formatting, and Python programs often read almost like plain English.

Today you should use Python 3. Python 2 stopped receiving updates in 2020, and new tutorials and libraries are written for Python 3.

What is Python used for?

Because Python is flexible and has a very large collection of libraries, it shows up in many fields:

  • Web development: frameworks such as Django and Flask are used to build websites and web services.
  • Data analysis and visualization: libraries such as NumPy, pandas and Matplotlib handle numbers, tables and charts.
  • Machine learning: many popular machine learning tools have Python interfaces.
  • Automation and scripting: renaming files, sending emails, reading spreadsheets or collecting data from websites.
  • Electronics and hardware: Python can read sensors, talk to microcontrollers over a serial port and run on small computers such as the Raspberry Pi.
  • Image processing: the OpenCV library can be used from Python to open, change and analyze images and video.
See also
LED CONTROLLING USING ARDUINO AND PYTHON

Since emergingtechs.org covers gadgets and electronics, the hardware side is worth a closer look. Python is popular with makers because a few lines of code can read a sensor, log the values and plot them. If you own a Pi, our list of Raspberry Pi Python projects shows what is possible at different skill levels.

Why people choose Python

It is easy to read

Python code is short compared with many other languages. A task that takes many lines elsewhere often takes only a few in Python. This helps beginners, and it also makes other people’s code easier to understand later.

It has a large ecosystem

The Python Package Index (PyPI) hosts a huge number of third-party packages, and you install them with the pip tool. Before writing something from scratch, it is worth checking whether a well-maintained library already does the job.

It has a helpful community

Python is widely used and taught, so you can usually find documentation, tutorials and answered questions for the problem you are stuck on.

Where it is weaker

Python is not the best choice for everything. Because it is interpreted, it is usually slower than compiled languages such as C. It is also less common for programs that must run in very small, time-critical embedded systems, though variants such as MicroPython exist for certain microcontrollers. If you are deciding between the two, see our comparison of C language vs Python.

How to install Python

  1. Go to the official Python website, python.org, and download the latest Python 3 release for your operating system.
  2. Run the installer. On Windows, tick the option to add Python to your PATH so you can run it from the command line.
  3. Open a terminal or command prompt and type python –version (on some systems python3 –version) to confirm it is installed.
  4. Choose an editor. IDLE comes with Python, and many people also use editors such as Visual Studio Code or PyCharm.
See also
FOR LOOP IN PYTHON

Linux and macOS often include a version of Python already, but it may be old or reserved for system tools. Installing a current Python 3 yourself is a safer starting point.

Your first Python program

The traditional first program prints a message on the screen. Create a file named hello.py, add the line print(‘Hello, world!’), save it, and run it with python hello.py in your terminal. If you see the message, your setup works.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

You can also type python on its own to open the interactive shell. It runs one line at a time, which is handy for testing small ideas.

Core concepts to learn first

Most beginners work through the same set of basics. Learn these in roughly this order:

  • Variables and data types: numbers, strings (text), booleans, lists, tuples and dictionaries.
  • Input and output: showing results with print() and reading what a user types with input().
  • Decisions: using if, elif and else to run code only when a condition is true. Our guide to the if statement in Python covers this.
  • Loops: repeating work with for and while. See the while loop in Python for a walkthrough.
  • Functions: reusable blocks of code defined with def.
  • Modules and packages: importing code from the standard library or from packages you install with pip.
  • Files and errors: reading and writing files, and handling problems with try and except.

If you want a step-by-step path, start with our article on getting started with Python and then move on to the topics above.

Tips for learning Python faster

  • Write code every day. Short, regular practice works better than occasional long sessions.
  • Build something small. A unit converter, a to-do list or a script that reads a sensor teaches more than reading alone.
  • Read error messages. Python usually tells you the line and the type of the problem.
  • Use virtual environments. The built-in venv module keeps each project’s packages separate and avoids version conflicts.
  • Read other people’s code. Open source projects show how experienced developers structure programs.
See also
WHILE LOOP IN PYTHON

Frequently asked questions

Is Python good for beginners?

Yes. Its readable syntax and large amount of learning material make it one of the easier languages to start with. You can write useful programs after learning only a few basic concepts.

Is Python free?

Yes. Python is open source and free to download and use, including for commercial projects. Most of the popular libraries are free as well.

Should I learn Python 2 or Python 3?

Learn Python 3. Python 2 reached end of life in 2020 and no longer gets updates, so it is only relevant if you have to maintain very old code.

Can Python be used with Arduino and Raspberry Pi?

Yes. On a Raspberry Pi you can run Python directly. With an Arduino, a common approach is to run Python on your computer and exchange data with the board over a serial connection using a library such as pySerial.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works