convert ints in a range to strings

Michael Sweeney starbuck_ms at yahoo.com
Wed Sep 17 23:59:45 EDT 2003


> Hi,
> 
> I'm trying to do this:
> 
> ------------------------------
> a="192."
> b="168."
> c="1."
> r = range(256)
> for r in r:
> 	print a + b + c + r
> ------------------------------
> 

You could try this:

a="192"
b="168"
c="1"
for d in range(256):
    print "%s.%s.%s.%s"%(a,b,c,d)


192.168.1.0
192.168.1.1
192.168.1.2
192.168.1.3
...
192.168.1.255

- Mike




More information about the Python-list mailing list