Python problem using . Join

Asked

Viewed 98 times

0

I need to print a MAC address, with tab ' : ', but I can only print the address with the tab at each string box, and the MAC address separates every 2 houses.

2 answers

0

If it’s just for screen printing, you can try a simpler solution:

>>> addr='0a1b2c3d4e5f'
>>> '{0}{1}:{2}{3}:{4}{5}:{6}{7}:{8}{9}:{10}{11}'.format(*addr)
'0a:1b:2c:3d:4e:5f'

0


If you’re gonna use .join then this solution will suit you:

>>> ':'.join([addr[x-2:x] for x in range(2, len(addr)+2,2)])
'0a:1b:2c:3d:4e:5f'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.