Python dynamic typing
It seems that python uses polymorphism, similar to javascript to allow dynamic typing. What this basically means is that you don’t have to declare the type of variable you create, like you would in Java or C. Under the hood, a variable gets assigned to an object in memory that has a field for its type (which references another object that represents all of those types) and space for its actual value. The variable name doesn’t need to be typed because its only a pointer in memory to that object. This reminds me of javascript, where an object has a prototype chain to the ‘object of ...’ ie. the object of all Arrays. That’s similar to what’s happening in python, where an object’s type references an ‘object of ints’ or something. As I learn python, I understand why things in Javascript is the way they are. I see there is a history of how computer languages came to be, from
C -> Python -> Javascript
When I only learned Javascript it didn’t make too much sense, but now I see it from the point of view as, if I were to make a language from scratch, how would I implement variable types? It totally makes sense to point them to one global variable type. Any immutable types (numbers, strings, tuples) don’t share pointers. So if you point two variables at the same value they will make independent copies that don’t change if you modify the other. a = ‘string’ b = a a = 2 print(b) // ‘string’ Python under the hood wont immediately delete small numbers or strings and keep them in memory in case they are referenced later. The opposite is true for mutable types, (sets, dictionaries, lists) if you have two variables sharing a pointer to the same object, mutating that value will change it everywhere.













