Edouard Renard

Python vs C++, which should you choose? Python and C++ are both proven languages that are used by almost any IT company in the world. But let’s pause for a second here and ask the real question. If you’re reading this, you probably want to know:

For this post, I’m going to use a very practical approach. Who really cares about getting all the possible small technical details? What you want is the big picture, and some helpful recommendations from someone with real-world experience, so you can make a good choice.

Let’s get something clear first. A programming language is just a tool. When you learn how to program, you don’t learn a “language.” You learn how to solve problems in an efficient way, using code as a means to an end.

Give an experienced carpenter a new hammer and they will be able to use it much better than any newbie around, even if they have never used this specific hammer before. Well, it works the same for programming.

Practical Python: Learn Python Basics Step by Step- Python 3

Last Updated April 2022

  • 54 lectures
  • Beginner Level
4.5 (36)

Get started quickly with Python (Python 3): Only Hands-on Lessons and Practice to Master Python basics. | By Edouard Renard

Explore Course

So let’s get started and see what the practical differences are between the Python tool and the C++ tool when it comes to solving problems.

Similarities between Python and C++

Both Python and C++ are very mature languages. Python was created in 1991, and C++ in 1979. Both languages have remained popular through the years and experienced many changes, but they are now both mature and stable — possibly more stable than some other languages that are victims of “hey, let’s create a new flashy framework every six months.”

Both languages are very popular. Python is actually more popular than C++ (2.5* more Python questions than C++ questions on StackOverflow, for example), but overall, both are in the top five more popular languages (source: IEEE).

Both languages have the potential to get you a high-paying job. I’m not going to include numbers here, because salaries vary a lot depending on where you live in the world and what kind of company you want to work for (unfortunately not every company in the world is a U.S.-based company paying U.S. dollars, which is what we often find in “salary studies”). All I can tell you is that if you get good at any language, then you can potentially get paid very well.

When it comes to the technical aspects, both C++ and Python are Object-Oriented Programming languages. Object-Oriented Programming (OOP) is a paradigm (a way to program) used almost everywhere. What this means is that once you know OOP for one language, you can use the same concepts for another language.

Let’s now focus on the differences between Python and C++ when it comes to ease of use and performance. After this, we can look at why one language is better suited for a certain type of application than the other.

Ease of learning/coding — Python wins

We have a clear winner here: Python. And why is that?

Python programming is less strict than C++ programming, and you’ll write fewer lines of code for the same output.

Python is:

C++ is:

Now, what does that mean?

So, learning Python is going to be faster than learning C++. And usually, for the same program, the Python source code will be something around five times smaller than the C++ source code. If you know both languages, and you have the option to use them both for the same application (more on that later), programming with Python is also probably going to make the process of writing the code quicker.

As a quick illustration, here are two videos showing you how to get the user input with Python and C++, so you can see how many lines you need and how complicated the programs look.

Get the user input with Python:

Get the user input with C++:

Execution speed — C++ wins

Well, you can’t have it all. If Python is the winner when it comes to the ease of use, C++ will completely destroy Python on execution speed. C++ is faster than Python. The main reason for this is that Python is an interpreted language, and C++ is a compiled language.

When you execute a Python program, the Python interpreter is going to read each line one by one, and execute it on the fly. In C++, you first compile all the code into a binary executable. The compiler is going to optimize a lot of things. And running a binary program is much faster for a computer than reading a text document and analyzing each line one by one.

All the ease of use you get with Python is also the price you pay when it comes to performance. Now, don’t get me wrong here: It’s not because C++ is faster that you should use it by default. It all depends on the application you are going to use it for. If Python is fast enough for what you need, then use Python. As Donald Knuth said: “Premature optimization is the root of all evil.” Don’t make your life more complicated without a good reason.

Python and C++ binding

One thing I want to quickly explain before we go further is that you can bind Python and C++ code. That is, you can write Python code that can call a C++ algorithm. This way, you benefit from the ease of use of Python (on the interface level) and the performance of C++.

The great thing is that when you use the Python module, you don’t even know that some C++ code is being executed. This is a pretty common practice, and with this, “Python vs C++” becomes “Python AND C++.” Many Python libraries actually use this technique.

So, be aware of that: It’s not because you’re writing code in Python that you’re not using C++! And this is something we’re going to encounter quite often in the following applications.

Python vs C++ for different application types

OK, we are now clear on two points:

Now, there is another factor you need to take into account. This factor is what type of application you are going to use it for. Some kinds of applications have a very strong Python community, Python libraries/frameworks, and Python courses/tutorials. For other fields, C++ will prevail.

So, what I’m telling you is that for certain types of applications, you don’t even need to think about Python vs C++. Simply because one of them is clearly favored and already working better with a complete ecosystem/community/etc. behind it.

For some types of applications, you will still have a choice, and then you can use the “ease of use/performance” ratio to decide what’s worth your time.

Back-end web development

Web development is one of the biggest niches in software development. At this point, it’s not even a niche but a complete industry. And if you’re working on the back-end part of web development (server side), Python is the most used, along with JavaScript and other new languages, but in this post, we stick to Python and C++. Writing back-end code with C++ will take you much longer than with Python. With Python, you also get some well-tested and proven frameworks like Django and Flask.

One exception here: If you’re working on some specific kind of engine running in the background that is used by your Python framework, you might develop with C++. And guess what? In this case, you’d use a Python and C++ binding, so that both languages work together.

Artificial intelligence and data science

For artificial intelligence (AI) and data science, Python is also a winner. Many of the most popular data science libraries are available in Python. Combine these with the ease of use of Python and you will be writing code to analyze data in a very short amount of time.

If you want to go deeper and write your own algorithm and engines, you’ll probably have to use C++. In data science and artificial intelligence, as you can guess, you need speed.

So here’s what to do: Use Python when you are using AI and data science libraries, but use C++ to develop your own complex algorithms. In the later case, use the Python and C++ binding to make your C++ algorithm available from the Python interface.

If you thought you were done with the “Python vs C++” question for data science, wait for it! Python and C++ are not the only languages you can use. For example, R is a quite popular language for data science. So, the question can also be: Should you use R or Python?

Embedded systems

The closer you get to hardware, the more performance you need. And here the answer is quite simple: almost any microcontroller you program will require you to write in C++. Python just does not exist in embedded systems. A very popular microcontroller is the STM32 family. It’s very powerful, but also with a steep learning curve. If you want to get started with the world of microcontrollers, you can have a look at Arduino for a gentler learning path.

Robotics

Robotics is a large ecosystem. It combines many fields: electronics, software engineering, mechanics, artificial intelligence, and more. In robotics, the “Python vs C++” question can be quite tricky, because you can usually use both languages (or a combination of both) to write an application for a robot.

You will use:

So, which one to choose: Python or C++?

Rapid prototyping is a big part of robotics, so Python is very useful. What you can do (and what I personally do) is go with Python first to prototype the code as fast as possible. What you want to do is show that the idea is working with a proof of concept and build a working prototype as fast as possible. Performance doesn’t matter at this stage. 

Once you have validated the idea, you can build the real production code with C++ when you need performance. It’s all a question of costs: In the short term, you want to optimize your time cost. In the long term, you want to optimize the hardware cost for the product (for possible mass production).

Video games

You can start writing some small games with Python, but if you want to be serious, you are going to use C++. Video games use a lot of computer resources, and you have to use the fastest tool available to you. Many game engines are written in C++. The video game community is also very heavily C++-oriented, which means you’ll find way more tutorials, courses, and libraries in C++ than you will in Python.

What to choose: Python vs C++?

Let’s have a quick recap.

If you’ve never coded in your life:

Now, if you’re looking for which language to use for your next project, then it really depends on what kind of project you’re building:

One thing you can’t go wrong with: learn both Python and C++. As you could see in the few examples above, there is no black-and-white answer to this question. You will often need the combination of both languages. And what’s the good news here? Well you can learn those two languages in a practical way, with these Practical Python and Practical C++ courses for beginners.

Page Last Updated: April 2022

Top courses in Python

Python for Data Science and Machine Learning Bootcamp
Jose Portilla
4.6 (120,734)
Bestseller
Machine Learning A-Z™: Hands-On Python & R In Data Science
Kirill Eremenko, Hadelin de Ponteves, Ligency I Team, Ligency Team
4.5 (162,156)
The Modern Python 3 Bootcamp
Colt Steele
4.7 (26,914)
Python for beginners
Bharath Thippireddy
4.4 (20,900)
Learn Python & Ethical Hacking From Scratch
Zaid Sabih, z Security
4.6 (16,347)
The Complete Python Course | Learn Python by Doing in 2022
Codestars • over 2 million students worldwide!, Jose Salvatierra, Rob Percival, Teclado by Jose Salvatierra
4.6 (17,990)
Python in Containers
Kris Celmer
4.6 (321)
Bestseller
Artificial Intelligence: Reinforcement Learning in Python
Lazy Programmer Team, Lazy Programmer Inc.
4.8 (9,265)
Bestseller

More Python Courses

Python students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.

Request a demo

Courses by Edouard Renard

Programming the Arduino - Getting Started
Edouard Renard
4.8 (1,007)
Bestseller
ROS Actions
Edouard Renard
4.8 (96)
Highest Rated
ROS2 For Beginners (ROS Foxy, Humble - 2022)
Edouard Renard
4.7 (899)
Bestseller
Raspberry Pi For Beginners - 2022 Complete Course
Edouard Renard
4.6 (915)
Bestseller
Arduino For Beginners - 2022 Complete Course
Edouard Renard
4.6 (765)
Bestseller
Raspberry Pi and Arduino - Go to The Next Level
Edouard Renard
4.6 (72)
Bestseller
Practical Linux Command Line 2.0
Edouard Renard, Codestars • over 2 million students worldwide!
4.7 (44)

Courses by Edouard Renard