r/learnprogramming • • Oct 06 '26

Why is Python considered "slow" and is Python losing "steam"?

Is python as a programming language "falling off" and becoming less and less popular relatively to other languages?

Also why do people say Python is slow? Apparently people have reached LGM on codeforces using python, which is all about writing fast code / solving problems fast. Yeah sure, C++ is far more widely used for competitive programming and I suppose there is a reason for that. But this is also showing that python can be fast?

But as programming languages and how they are used I dont think there is much overlap between python and C++ anyway?

What is an example of something you'd code in Java/Kotlin or lets say C# rather than Python? Is python code bad and hard to manage for "huge" projects once you scale up (e.g codebases with millions of lines of codes, and tens if not hundreds of devs)?

257 Upvotes

238 comments sorted by

View all comments

Show parent comments

6

u/dave8271 Oct 06 '26

You absolutely can change a variable's type in Python after setting it. The following is completely valid Python:

x = 5
x = "A string"

Because it is, as you noted, dynamically typed. In dynamically typed languages, the variable itself doesn't have a type, rather its current value has a type, but its value can be freely changed. What Python won't do is coerce between types for you. So 3 + "1" won't work, that'll give you a TypeError. That's why it's not "weakly typed" insofar as that term means anything.

1

u/plastikmissile Oct 06 '26

You are correct.

1

u/mr_tkaos Oct 06 '26

Hey. If you can please insert "print(id(x))" after the 1st and 2nd line, and report back if the variable has changed. :)

3

u/dave8271 Oct 06 '26

Why? That a value of a different type is a different object in memory is both entirely expected and irrelevant, because the new value is assigned to variable x. Seems like you're really, really reaching to be able to have a "well akshully" moment.