String Format Printing With Python3: How To Print From Array?
Python3 has the super string.format printing: '{} {}'.format('one', 'two') If my strings are in an array, one way would be to type them out: a = ['one','two'] '{} {}'.format(a[0],
Solution 1:
Use unpacking to expand the array during the function call.
print(hex_string.format(*letters))
Output:
_____
/ \
/ \
,----( 1 )----.
/ \ / \
/ 2 \_____/ 3 \
\ / \ /
\ / \ /
)----( 4 )----(
/ \ / \
/ \_____/ \
\ 5 / \ 6 /
\ / \ /
`----( 7 )----'
\ /
\_____/
Solution 2:
Try unpacking the elements of the list using *
as following. For example, printing would look like
print ('{} {}'.format(*a))
# one two
Solution 3:
Use the *
notation for lists:
print(hex_string.format(*letters))
Post a Comment for "String Format Printing With Python3: How To Print From Array?"