def is_valid_partition(part):
 regex = re.compile('/dev/sd[a-z][1-9][0-9]?$')
 try:
  return (regex.match(part) is not None)
 except TypeError:
  return False

def is_valid_partition ( part ) : regex = re . compile ( '/dev/sd[a-z][1-9][0-9]?$' ) try : return ( regex . match ( part ) is not None ) except TypeError : return False
checks that part matches the following regular expression: /dev/sd[a-z][1-9][0-9]?$ .