0

I'm trying to change every value of a variable with a specific function

For that I tried this:

 Value = 0

 def ChangeValue(Variable):
     Variable = 1

 ChangeValue(Value)

 print(Value)

It actually should outcome 1, but it doesn't. What am I doing wrong ?

0

1 Answer 1

0

Variable inside of ChangeValue() is its own "box" with its own value. When you pass Value to ChangeValue(), you take the value from Value and put it in Variable. Changing the value of Variable does not affect the value of Value. This is what many languages call pass-by-value.

Sign up to request clarification or add additional context in comments.

4 Comments

Okay, and how can I change it over the function ?
@Alex To answer that, I need more detail about what you are really trying to do. I appreciate that you made your original example simple. However, you seem to have simplified too far and left out some important details.
@Alex What I am trying to say is that changing a variable in the way you want is not allowed in Python. There is probably some different solution to your original problem that will work.
Okay, thats enough I need to know

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.