Python short course: String formatting output

 String in Python also support formatting output like below:



In [1]: '%s, eggs, and %s' % ('spam', 'SPAM')
Out[1]: 'spam, eggs, and SPAM'

In [2]: '{0}, eggs, and {1}'.format('spam', 'SPAM')
Out[2]: 'spam, eggs, and SPAM'

In [3]: '{}, eggs, and {}'.format('spam', 'SPAM')  #numbers are optional
Out[3]: 'spam, eggs, and SPAM'

Comments

Popular posts from this blog

Lab's weekly topic - week 50 2023 - Detailed explanation for encoder of U-Net

Lab's weekly topic - week 49, 2023 - What's limitations and possible solutions for a new AI tools to detect blood poisoning?

Lab's recommendation: Awesome books to learn machine learning and AI (continue updating)