# What's the difference between f[x_]= ... and f[x_]:=...

Posted 8 years ago
12229 Views
|
2 Replies
|
3 Total Likes
|
 thanks
2 Replies
Sort By:
Posted 8 years ago
 RandomInteger[10] is a command that produces a random number from 0 to 10. Evaluate RandomInteger[10] a bunch of times till you have a feel for what it does. Now evaluate this command: myRandomNumber = RandomInteger[10]  Play around with myRandomNumber. How does myRandomNumber behave? myRandomNumber is always the same number. The right hand side of the equal sign was evaluated once and became the value for myRandomNumber. Now evaluate this command: myOtherRandomNumber := RandomInteger[10]  Play around with myOtherRandomNumber. How does it behave? myOtherRandomNumber is always a different number. The right hand side of the equal sign re-evaluates every time you call myOtherRandomNumber.
Posted 8 years ago
 yes there is, the := notation reevaluates the right-hand-side each time it is evaluated. So there is a difference between these two definitions: ClearAll[p,f] p=2; f[x_]:=x+p; p=3; f[2] ClearAll[p,f] p=2; f[x_]=x+p; p=3; f[2]