title: How does self.next = None get the next value of l1?
body: <p>I was working on one of the problems on Leetcode (problem 21). It asks me to merge two sorted linked lists and return it as a new list, and it gives pre-typed code like this.</p>
  
  <pre><code># Definition for singly-linked list.
  # class ListNode(object):
  #     def __init__(self, x):
  #         self.val = x
  #         self.next = None
  
  class Solution(object):
      def mergeTwoLists(self, l1, l2):
          """
          :type l1: ListNode
          :type l2: ListNode
          :rtype: ListNode
          """
  </code></pre>
  
  <p>I did some test before formally solving merging problem. I input l1 as following:</p>
  
  <pre><code>l1 = [1,2,3,4,5]
  </code></pre>
  
  <p>and I changed the code into:</p>
  
  <pre><code>class Solution(object):
      def mergeTwoLists(self, l1, l2):
          print(l1.val)
          print(l1.next.val)
  </code></pre>
  
  <p>The output shows:</p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>The part that confused me is how does function self.next get the next value of the ListNode that I input. In my understanding, self.next is set to None, so l1.next should equal to None, and None.val should go wrong. Could someone help me with this?</p>
  
  <p>Here are two pictures that show the code, input, and output.</p>
  
  <p><a href="https://i.stack.imgur.com/ueXbX.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>Also, here is the link where I get my problem.
  <a href="https://leetcode.com/problems/merge-two-sorted-lists/#/description" rel="nofollow noreferrer">https://leetcode.com/problems/merge-two-sorted-lists/#/description</a></p>