13 KiB
13 KiB
In [ ]:
print("I'm going to inject %s here." %'something')In [ ]:
print("I'm going to inject %s text here, and %s text here." %('some','more'))In [ ]:
x, y = 'some', 'more'
print("I'm going to inject %s text here, and %s text here."%(x,y))In [ ]:
print('He said his name was %s.' %'Fred')
print('He said his name was %r.' %'Fred')In [ ]:
print('I once caught a fish %s.' %'this \tbig')
print('I once caught a fish %r.' %'this \tbig')In [ ]:
print('I wrote %s programs today.' %3.75)
print('I wrote %d programs today.' %3.75) In [ ]:
print('Floating point numbers: %5.2f' %(13.144))In [ ]:
print('Floating point numbers: %1.0f' %(13.144))In [ ]:
print('Floating point numbers: %1.5f' %(13.144))In [ ]:
print('Floating point numbers: %10.2f' %(13.144))In [ ]:
print('Floating point numbers: %25.2f' %(13.144))In [ ]:
print('First: %s, Second: %5.2f, Third: %r' %('hi!',3.1415,'bye!'))In [ ]:
print('This is a string with an {}'.format('insert'))In [ ]:
print('The {2} {1} {0}'.format('fox','brown','quick'))In [ ]:
print('First Object: {a}, Second Object: {b}, Third Object: {c}'.format(a=1,b='Two',c=12.3))In [ ]:
print('A %s saved is a %s earned.' %('penny','penny'))
# vs.
print('A {p} saved is a {p} earned.'.format(p='penny'))In [ ]:
print('{0:8} | {1:9}'.format('Fruit', 'Quantity'))
print('{0:8} | {1:9}'.format('Apples', 3.))
print('{0:8} | {1:9}'.format('Oranges', 10))In [ ]:
print('{0:<8} | {1:^8} | {2:>8}'.format('Left','Center','Right'))
print('{0:<8} | {1:^8} | {2:>8}'.format(11,22,33))In [ ]:
print('{0:=<8} | {1:-^8} | {2:.>8}'.format('Left','Center','Right'))
print('{0:=<8} | {1:-^8} | {2:.>8}'.format(11,22,33))In [ ]:
print('This is my ten-character, two-decimal number:%10.2f' %13.579)
print('This is my ten-character, two-decimal number:{0:10.2f}'.format(13.579))In [ ]:
name = 'Fred'
print(f"He said his name is {name}.")In [ ]:
print(f"He said his name is {name!r}")In [ ]:
num = 23.45678
print("My 10 character, four decimal number is:{0:10.4f}".format(num))
print(f"My 10 character, four decimal number is:{num:{10}.{6}}")In [ ]:
num = 23.45
print("My 10 character, four decimal number is:{0:10.4f}".format(num))
print(f"My 10 character, four decimal number is:{num:{10}.{6}}")In [ ]:
num = 23.45
print("My 10 character, four decimal number is:{0:10.4f}".format(num))
print(f"My 10 character, four decimal number is:{num:10.4f}")In [ ]:
In [ ]: