Skip to content

Instantly share code, notes, and snippets.

@pjastr

pjastr/a1.py Secret

Created March 14, 2022 17:17
Show Gist options
  • Save pjastr/d42d937c7b00b80b5dfe309b4ac0e854 to your computer and use it in GitHub Desktop.
Save pjastr/d42d937c7b00b80b5dfe309b4ac0e854 to your computer and use it in GitHub Desktop.
# source: https://realpython.com/python-formatted-output/#the-python-string-format-method
print('{quantity} {item} cost ${price}'.format(quantity=6, item='bananas', price=1.74))
print('{0}/{1}/{2}'.format('foo', 'bar', 'baz'))
print('{2}.{1}.{0}/{0}{0}.{1}{1}.{2}{2}'.format('foo', 'bar', 'baz'))
# print('{3}'.format('foo', 'bar', 'baz'))
print('{}/{}/{}'.format('foo', 'bar', 'baz'))
# print('{}{}{}{}'.format('foo','bar','baz'))
print('{}{}'.format('foo', 'bar', 'baz'))
# print('{1}{}{0}'.format('foo','bar','baz'))
print('{x}/{y}/{z}'.format(x='foo', y='bar', z='baz'))
# print('{x}/{y}/{w}'.format(x='foo', y='bar', z='baz'))
print('{0}/{1}/{2}'.format('foo', 'bar', 'baz'))
print('{0}/{1}/{2}'.format('bar', 'baz', 'foo'))
print('{x}/{y}/{z}'.format(x='foo', y='bar', z='baz'))
print('{x}/{y}/{z}'.format(y='bar', z='baz', x='foo'))
print('{0}{x}{1}'.format('foo', 'bar', x='baz'))
# print('{0}{x}{1}'.format('foo', x='baz', 'bar'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment