title: Python list reference and just another copy
body: <p>I wish to bring that last k elements of 'nums' array to the first. Like, Input:</p>
  <pre><code>nums = [1,2,3,4,5,6,7], k = 3
  </code></pre>
  <p>Output:</p>
  <pre><code>[5,6,7,1,2,3,4]
  </code></pre>
  <p>I have the following code:</p>
  <pre><code>class Solution(object):
      def rotate(self, nums, k):
          &quot;&quot;&quot;
          :type nums: List[int]
          :type k: int
          :rtype: None Do not return anything, modify nums in-place instead.
          &quot;&quot;&quot;
          n = len(nums)
          k = k % n
          nums[:] = nums[n-k:] + nums[:n-k]
  </code></pre>
  <p>This works perfectly fine i.e. brings the last k elements to the beginning and nums shows [5,6,7,1,2,3,4]. But once I type the following <code>nums = nums[n-k:] + nums[:n-k]</code>, it shows the resultant nums array as being the same original [1,2,3,4,5,6,7].</p>
  <p>My question is, why is the change in output taking place? On googling and upon reding certain other threads in this forum pertaining to 'List Referencing and copying', I could realize that <code>nums = </code> is something about list referencing but <code>nums[:]</code> is like a mere copy of the list. But having said thiat, why is this change in output taking place? What's happening inside both the commands?</p>
  <p>Seems like <code>nums</code> and <code>nums[:]</code> aren't yet clear to me. Please help.</p>