How does Python handle static and dynamic variables?

3

Static variable, is the one where we have separated the memory of the computer already beforehand in a defined way (I read this in the book "Basic structure of data"). The dynamic variable is the one in which it appears in the execution of the program, also known as "anonymous variables". These nodes only have access from the address.

    
asked by anonymous 16.10.2018 / 18:22

1 answer

5
Python is a dynamic typing language exclusively, there is no static typing, at least not in the default language (it has some variations that even have, but they are dialects, they can not be considered Python of truth, they have different semantics). There are even languages that have gradient types or optional dynamism, but that's not the case with Python.

So first you need to understand about these two typing styles that languages adopt. Also about What is typing style? .

Python is even deploying type annotation so that some errors can be identified at compile time, but typing will still be dynamic. There will be no performance gain, although in some cases they may create some optimization, but you can not tell that the variable will always have the same type, that is a significant semantic change and incompatible with what language is today.

So Python only deals with dynamic variables. All of them can have values of any kind at any given time. What you can not do is have more than one type at a time, and the value does not exist without type, even if it is not explicitly declared. In addition, it has strong typing, so it does not make insecure coercion that may present an unexpected result.

The current implementation of the language uses a structure for all values that contains the value and type of the value. In C (Python is written in C) this is usually done with a struct with a member of type and another member that is a union that overlaps the value of type.

Nearly everything in the commentary is wrong or confusing or out of context, as is the premise of the question. There is no anonymous variable in the concept we use, variable is a name by definition , it is a memory location with name. So it's hard to talk about misinformation. If we only have the address we have no variable, we can have the address in some variable, if the address is not in variable is only a value and if there is a value somewhere and does not have a reference with a name for it we do not have a variable .

The memory is reserved for values according to their type, always.

The variable is a concept of development time, it does not exist when it is running, variable is too abstract a concept to be present during execution that is something very concrete.

Here on the site you have a lot of information on this and I suggest you search more. The font that is used is either bad, or it is misinterpreting it.

    
16.10.2018 / 18:59