Python. I'm so curious.

Asked 2 years ago, Updated 2 years ago, 13 views

In Python, a = 1 and b = 1 are both the same addresses that point to 1 and a = 1 outside the function

For example, in C language,

After declaring a function, a = 1 disappears without a return, right?
By the way, Python is a pointer to the address a = 1b = 1, but why is a = 1 in the function incompatible with a = 1 outside the function? How does a=1 differ from a=1 outside the function?

python

2022-09-21 15:52

3 Answers

The scalar (default) type in Python copies the value if it is a variable scope problem or if it is a problem caused by parameter transfer of a function.

https://hashcode.co.kr/questions/7926/%ED%8C%8C%EC%9D%B4%EC%8D%AC-%EB%B3%80%EC%88%98%EC%9D%98-%EB%B2%94%EC%9C%84-%EA%B4%80%EB%A0%A8-%EC%A7%88%EB%AC%B8

See the link above.


2022-09-21 15:52

a=1 in a function and a=1 outside the function are the same values, but a in the function is stored as a local variable a and a outside the function is classified differently.

This is an answer to my question that I understood the explanation of my friend who started the promming first. As expected, friends are the best.


2022-09-21 15:52

In the programming paradigm, the conditions of the function are as follows.

The function shall not have any effect on the main function, and the function receives the result only as a return value.

Therefore, the area where Function runs is distinguished from the original program area. Function runs, and all the information in that area is no longer needed, so you don't need to remember it.

For Python, the file that runs is the main function.

This is because it distinguishes between local and global variables. Now, each programming language depends on how you implement it and what kind of paradigm you do, but you generally distinguish between regional and global variables.

Now, we can understand that it's a procedure to treat everything as a global variable without distinguishing between regional variables and global variablesOh, my. Stack frame go.


2022-09-21 15:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.