Verifying IPv6 addresses While trying to learn Python I stumbled upon a question which asks you to write a code that is able to take an input and verify it to see whether it meets the IPv6 Criteria. 

I wrote the following code:

valid_characters = ['A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f', ':', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
address = input('Please enter an IP address: ')
is_valid = []

for i in range(len(address)):
    current = address[i]
    for j in range(len(valid_characters)):
        check = valid_characters[j]
        if check == current:
            a = 1
            is_valid.append(a)

address_list = address.split(":")
invalid_segment = False

for i in range(len(address_list)):
    current = address_list[i]
    if len(current) &gt; 4:
        invalid_segment = True

if len(address) == len(is_valid) and len(address_list) == 8 and invalid_segment == False:
    print("It is a valid IPv6 address.")

elif invalid_segment:
    print("It is not a valid IPv6 address.")

else:
    print("It is not a valid IPv6 address.")


Although the code works and for the sample cases that were provided it is successfully able to confirm whether the entered IP address is IPv6 or not, I feel like my solution is not really elegant enough and that there should be a better way to do this.

I would really appreciate it if someone could point me to the right direction for how I should condense or improve my code. 

Please note that I am new to Python, with little to no experience.
Python has a philosophy of "Batteries Included".  Don't reinvent what's in the standard library!

In particular, this code is much more easily written if we take advantage of IPv6Address:

import ipaddress

address = input('Please enter an IP address: ')

try:
    addr = ipaddress.IPv6Address(address)
except ipaddress.AddressValueError:
    print(address, 'is not a valid IPv6 address')
else:
    if addr.is_multicast:
        print(address, 'is an IPv6 multicast address')
    if addr.is_private:
        print(address, 'is an IPv6 private address')
    if addr.is_global:
        print(address, 'is an IPv6 global address')
    if addr.is_link_local:
        print(address, 'is an IPv6 link-local address')
    if addr.is_site_local:
        print(address, 'is an IPv6 site-local address')
    if addr.is_reserved:
        print(address, 'is an IPv6 reserved address')
    if addr.is_loopback:
        print(address, 'is an IPv6 loopback address')
    if addr.ipv4_mapped:
        print(address, 'is an IPv6 mapped IPv4 address')
    if addr.sixtofour:
        print(address, 'is an IPv6 RFC 3056 address')
    if addr.teredo:
        print(address, 'is an IPv6 RFC 4380 address')