我有多个IP地址,范围从xxx.xx.xxx.11
到xxx.xx.xxx.50
。
对于IPAddress .11
,我想将字符串"A01"
分配给变量cabine
。
要对.12
进行IPAddress,字符串"A02"
etc直到.30
("A20"
)
然后,从IPAddress.31
,我想将字符串"B01"
,.32
{.50
{
虽然我是一个绝对的初学者,我认为这不会那么难,但它只是不想工作
我想用for循环编程,类似这样:
for (i = 11; i < 51; i++) {
cabine = A and something with i;
}
但我需要两个不同的循环,因为字母(A,B)不同,对吗? 提前感谢您的帮助
以下是您想要的示例:
使用
if
语句确定前缀A
或B
,以及循环索引如何转换为后缀号。然后使用格式化运算符添加前导零(请参见Best way to format integer as string with leading zeros?)要处理IP地址,可以使用
ipaddress
模块。.packed
成员可以访问IPV4Address
的每个号码。然后,您需要一个将IP地址转换为a/B和所需号码的公式输出:
相关问题 更多 >
编程相关推荐