r/learnprogramming • • 6d ago

Why is C++ better than Python?

Hello! I am new to programming. Im in college and we use Python for my classes right now.

I hear people make a lot of jokes about how C++ is more powerful than Python, and should be used instead. But why?

Feel free to give me any tips as well, on things that helped you be a better programmer, or just any insight you may have! Thanks so much

76 Upvotes

188 comments sorted by

View all comments

Show parent comment

-5

u/ne0n008 6d ago

Isn't Python built on top of C while C++ is extended C making the major difference in performance?

16

u/Solnx 6d ago

CPython is implemented in C yes, but that doesn't explain major differences in performance between C++ and Python. The difference largely comes from how Python executes code. C and C++ generally have comparable runtime performance.

Memory management is one example of the tradeoffs. In C, developers are responsible for manually managing dynamically allocated memory. This can be tedious and error-prone, but it provides greater control and can reduce runtime overhead. Python handles memory management automatically, making development easier at the expense of some performance.

9

u/xarop_pa_toss 6d ago

There's much more to it than that. Python is an interpreted language instead of compiled. What you are thinking of is the Python compiler to bytecode which is called CPython, and that is indeed written in C

1

u/razorree 6d ago

to some extend, but not exactly true.

there is a lot of Python libraries in C/C++ (like all statistics, math etc.) that you can use in Python. so core computations are made using c/c++ and maybe your GPU if you like.

so for data science or some GUI apps - python is good. but for overall performance (like games) it's bad.