How does Python handle static and dynamic variables?

Asked

Viewed 425 times

3

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

  • Clarify your question. What do you want to know specifically? What static variable are you talking about? Anyway, give more details about your question.

  • What you mean by "static variables" and "dynamic variables"?

  • Just making it clear that I am very much a baby in the IT area. I’m just crawling around.. Static variable, is the one where we separate the memory of the computer already defined beforehand (read this in the book "Basic data structure"). The dynamic variable, on the other hand, is one in which it appears in the execution of the program itself, also known as "anonymous variables". These, we only have access from the address.

1 answer

7


Python is a dynamic typing language exclusively, there is no static typing, at least not in the standard language (it has some variations that even have, but they are dialects, they cannot be considered real Python, they have different semantics). There are even languages that have graded types or optional dynamism, but this is not the case for Python.

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

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

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

The current language implementation uses a structure for all values that contain 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 the type and another member who is a union overlapping the value of the type.

Almost everything in the commentary is wrong or confused or without context, as is the premise of the question. There is no such thing as an anonymous variable in the concept we use, variable is a name by definition, is a memory position with a name. So it gets complicated 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 it is only a value and if there is a value somewhere and there is a reference with a name for it we do not have a variable.

Memory is reserved for values according to their type, always.

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

Here on the site there is a lot of information about it and I suggest researching more. The font that is used is either bad or is misinterpreting it.

  • Maniero, am I studying wrong ?

  • Perhaps, I cannot say this. If you give more details I could try to say something.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.