Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by patrec

3 years ago

It can mean two completely different things. `let x = x + 1` (rebinding) or `x += 1` (mutation).

    In [5]: def cap(x):  
       ...:     xs = [] 
       ...:     for i in range(3): 
       ...:         x+=1 
       ...:         xs.append(x) 
       ...:     return xs 
       ...:      
       ...:

    In [6]: cap(numpy.array(0))                                                                                                                                          
    Out[6]: [array(3), array(3), array(3)]
    In [7]: cap(0)                                                                                                                                          
    Out[7]: [1, 2, 3]

0 comments

patrec

Reply

No comments yet

Contribute on Hacker News ↗

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities