繁体   English   中英

Python:使用范围命令编辑 IP 地址

[英]Python: Edit IP address with range command

在 Python

I'd like to print a IP address with range 1 to 254 let say that my original IP is 123.345.4.222 I'd like the output to be: 123.345.4.1 123.345.4.2. . . 123.345.4.254

我已经运行了命令:

    IP_to_print = IP[:-3]
    for i in range(1, 255):
      IP_to_print =123.345.4.i
      print(IP_to_print)

问题:如何将变量“i”添加到值 IP_to_print? 所以打印将是:123.345.4.1.... 123.345.4.254

检查 python 的一些基础知识。

    IP_to_print = IP[:-3]
    for i in range(1, 255):
      IP_to_print =f"123.345.4.{i}"
      print(IP_to_print)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM