Right now I am having a list
>>> deints
[10, 10, 10, 50]
I want to print it as 10.10.10.50. I made it as
>>> print(str(deints[0])+'.'+str(deints[1])+'.'+str(deints[2])+'.'+str(deints[3]))
10.10.10.50
Are there any other ways we can acheivie this ?
Thank you
You can do it with:
print('.'.join(str(x) for x in deints))
This is very simple. Take a look at str.join
print '.'.join([str(a) for a in deints])
Citation from the docs:
str.join(iterable)
Return a string which is the concatenation of the strings in the iterable iterable. The separator between elements is the string providing this method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With