title: How to write same-name methods with different parameters in Python
body: <p>I'm learning Python (3.x) from a Java background.</p>
  <p>I have a Python program where I create a personObject and add it to a list.</p>
  <pre><code>p = Person(&quot;John&quot;)
  list.addPerson(p)
  </code></pre>
  <p>But for flexibility I also want to be able to declare it directly in the addPerson method, like so:</p>
  <pre><code>list.addPerson(&quot;John&quot;)
  </code></pre>
  <p>The addPerson method will be able to differentiate whether or not I'm sending a Person-object or a String.</p>
  <p>In Java I would create two separate methods, like this:</p>
  <pre><code>void addPerson(Person p) {
      # Add a person to the list
  }
  
  void addPerson(String personName) {
      # Create a 'Person' object
      # Add a person to the list
  }
  </code></pre>
  <p>I'm not able to find out how to do this in Python. I know of a type() function, which I could use to check whether or not the parameter is a String or an Object. However, that seems messy to me. Is there another way of doing it?</p>
  <p>I guess the alternative workaround would be something like this (Python):</p>
  <pre><code>def addPerson(self, person):
      # Check if 'person' is a string
          # Create a person object
  
      # Check that a person is a Person instance
          # Do nothing
  
      # Add person to list
  </code></pre>
  <p>But it seems messy compared to the overloading solution in Java.</p>