- 用法:- IPv4Address.__format__(fmt)
- 返回 IP 地址的字符串表示形式,由顯式格式字符串控製。 - fmt可以是以下之一:- 's',默認選項,等效於- str(),- 'b'用於零填充的二進製字符串,- 'X'或- 'x'用於大寫或小寫十六進製表示,或- 'n',相當於 IPv4 地址的- 'b'和 IPv6 的- 'x'。對於二進製和十六進製表示,格式說明符- '#'和分組選項- '_'可用。- __format__由- format,- str.format和f-strings 使用。- >>> format(ipaddress.IPv4Address('192.168.0.1')) '192.168.0.1' >>> '{:#b}'.format(ipaddress.IPv4Address('192.168.0.1')) '0b11000000101010000000000000000001' >>> f'{ipaddress.IPv6Address("2001:db8::1000"):s}' '2001:db8::1000' >>> format(ipaddress.IPv6Address('2001:db8::1000'), '_X') '2001_0DB8_0000_0000_0000_0000_0000_1000' >>> '{:#_n}'.format(ipaddress.IPv6Address('2001:db8::1000')) '0x2001_0db8_0000_0000_0000_0000_0000_1000'- 3.9 版中的新函數。 
相關用法
- Python ipaddress.IPv4Address.reverse_pointer用法及代碼示例
- Python ipaddress.IPv4Address用法及代碼示例
- Python ipaddress.IPv4Network.supernet用法及代碼示例
- Python ipaddress.IPv4Network.supernet_of用法及代碼示例
- Python ipaddress.IPv4Network.address_exclude用法及代碼示例
- Python ipaddress.IPv4Interface.ip用法及代碼示例
- Python ipaddress.IPv4Network.subnets用法及代碼示例
- Python ipaddress.IPv4Interface.with_prefixlen用法及代碼示例
- Python ipaddress.IPv4Interface.with_netmask用法及代碼示例
- Python ipaddress.IPv4Interface.with_hostmask用法及代碼示例
- Python ipaddress.IPv4Network.subnet_of用法及代碼示例
- Python ipaddress.IPv4Network.compare_networks用法及代碼示例
- Python ipaddress.IPv4Network.hosts用法及代碼示例
- Python ipaddress.IPv4Interface.network用法及代碼示例
- Python ipaddress.IPv6Address用法及代碼示例
- Python ipaddress.collapse_addresses用法及代碼示例
- Python ipaddress.summarize_address_range用法及代碼示例
- Python ipaddress.v4_int_to_packed用法及代碼示例
- Python ipaddress.ip_address用法及代碼示例
- Python numpy ipmt用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 ipaddress.IPv4Address.__format__。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
