If I want to specify ip = '192.168.0.1' variable and increase it sequentially like 192.168.0.2, 192.168.0.3, what should I do?
python
There are many ways.
for i in range(1, 100):
ip = f'192.168.0.{i}'
print(ip)
a = [1, 2, 3, 4, 55, 6, 7]
for i in a:
ip = f'192.168.0.{i}'
print(ip)
ip = '192.168.0.1'
list_ip = ip.split('.')
for i in range(int(ip[-1]), 100):
list_ip[-1] = str(i)
ip = '.'.join(list_ip)
print(ip)
I think it would be good to make the place of the ip into each variable.
ip = [192, 168, 0, 1]
for i in range(10):
ip[-1] += 1
print(".".join(map(str, ip)))
© 2024 OneMinuteCode. All rights reserved.