title: Using Python, how can we check if a string is a valid UUID?
body: <p>Given some string (e.g. <code>9c68ed68-1c80-4cf1-9ca9-477b5dd5fcb2</code>), how can we verify that it is a valid UUID4 using Python? I have yet to see a clear answer (e.g. <a href="https://stackoverflow.com/questions/19989481/how-to-determine-if-a-string-is-a-valid-v4-uuid">here</a> and <a href="https://stackoverflow.com/questions/45943754/how-to-validate-list-of-uuids-and-return-uuid-version">here</a>) - it seems like there is always some sort of caveat these solutions. Is there an acceptable way to accomplish this? The nicest I've seen so far is in the second link I mentioned, which simply checks for its version inside a try/except block. For example:</p>
  <pre><code>def check_uuid4(test_uuid, version=4):
      try:
          return uuid.UUID(test_uuid).version == version
      except ValueError:
          return False
  </code></pre>