Python Using format() To Automaticaly Put Space

When you append some variable maybe you will deal with problem like spacing. By using format() you can simplify the need of spacing for example like this :

>>> ipaddr='8.8.8.8'
>>> vrf='management'
>>> ping = 'ping'+ipaddr+vrf
>>> ping
'ping8.8.8.8management'

See the result above that all value is not appear space.

to solve this you can use format()
>>> ping='ping {} vrf {}'.format(ipaddr, vrf)
>>> print ping
ping 8.8.8.8 vrf management

great!

Tulis komentar anda... Conversion Conversion Emoticon Emoticon

Thanks for your comment