<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_tag(version: Union[Version, str], tag_format: Optional[str] = None):
 """The tag and the software version might be different. That's why this function exists. Example: | tag | version (PEP 0440) | | --- | ------- | | v0.9.0 | 0.9.0 | | ver1.0.0 | 1.0.0 | | ver1.0.0.a0 | 1.0.0a0 | """

    if isinstance(version, str):
        version = Version(version)

    if not tag_format:
        return version.public

    major, minor, patch = version.release
    prerelease = ""
    if version.is_prerelease:
        prerelease = f"{version.pre[0]}{version.pre[1]}"

    t = Template(tag_format)
    return t.safe_substitute(
        version=version, major=major, minor=minor, patch=patch, prerelease=prerelease
    )