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 ?

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
Alex
  • 39
  • 1
  • 10

1 Answers1

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.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Okay, and how can I change it over the function ? – Alex Feb 01 '18 at 23:24
  • @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. – Code-Apprentice Feb 01 '18 at 23:25
  • @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. – Code-Apprentice Feb 01 '18 at 23:26
  • Okay, thats enough I need to know – Alex Feb 01 '18 at 23:28