@@ -1547,6 +1547,30 @@ def __init__(self, address, strict=True):
15471547        elif  self ._prefixlen  ==  (self .max_prefixlen ):
15481548            self .hosts  =  lambda : [IPv4Address (addr )]
15491549
1550+     @property  
1551+     def  shorthand (self ):
1552+         """ 
1553+         Returns the shorthand representation of the IPv4 network. 
1554+ 
1555+         This method abbreviates the IPv4 network by removing trailing 
1556+         zero octets from the network address. 
1557+ 
1558+         Returns: 
1559+             str: The shorthand IPv4 network in the format 'X.X/X'. 
1560+ 
1561+         Example: 
1562+             >>> network = IPv4Network('192.168.0.0/24') 
1563+             >>> network.shorthand 
1564+             '192.168/24' 
1565+         """ 
1566+         # Split the network address into octets 
1567+         octets  =  str (self .network_address ).split ('.' )
1568+         # Remove trailing zero octets 
1569+         while  octets  and  octets [- 1 ] ==  '0' :
1570+             octets .pop ()
1571+         # Rejoin the remaining octets and append the prefix length 
1572+         return  '.' .join (octets ) +  f"/{ self .prefixlen }  " 
1573+ 
15501574    @property  
15511575    @functools .lru_cache () 
15521576    def  is_global (self ):
@@ -2341,6 +2365,24 @@ def hosts(self):
23412365        for  x  in  range (network  +  1 , broadcast  +  1 ):
23422366            yield  self ._address_class (x )
23432367
2368+     @property  
2369+     def  shorthand (self ):
2370+         """ 
2371+         Returns the shorthand representation of the IPv6 network. 
2372+ 
2373+         This method compresses the IPv6 address to its shortest form 
2374+         and appends the prefix length. 
2375+ 
2376+         Returns: 
2377+             str: The shorthand IPv6 network in the format 'X::/Y'. 
2378+ 
2379+         Example: 
2380+             >>> network = IPv6Network('2001:db8:0:0:0:0:0:0/32') 
2381+             >>> network.shorthand 
2382+             '2001:db8::/32' 
2383+         """ 
2384+         return  f"{ self .network_address .compressed }  /{ self .prefixlen }  " 
2385+ 
23442386    @property  
23452387    def  is_site_local (self ):
23462388        """Test if the address is reserved for site-local. 
0 commit comments