IPv4 Format Check

An IPv4 address looks simple, but its format has strict rules. Given a string ip, return True if it is a valid IPv4 address. It must contain exactly four dot-separated numbers, each from 0 to 255, with no leading zeroes and no extra characters. In all other cases, return False.

Примеры

Ввод
"192.168.0.1"
Вывод
True
Ввод
"0.0.0.0"
Вывод
True
Ввод
"255.255.255.255"
Вывод
True

Нужно реализовать

def is_valid_ipv4(ip):

Теги

strings
PostgreSQLv16

Le résultat de l'exécution du code s'affichera ici

Visible tests
1
Input
"192.168.0.1"
ExpectedTrue
2
Input
"0.0.0.0"
ExpectedTrue
3
Input
"255.255.255.255"
ExpectedTrue
4
Input
"256.1.1.1"
ExpectedFalse
5
Input
"1.2.3"
ExpectedFalse
6
Input
"01.2.3.4"
ExpectedFalse
Focus radio
Paused · SomaFM · Fluid