Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
23 Cards in this Set
- Front
- Back
What is the basic way that positional formatting is done in Python? |
'{}'.format(a) |
|
a='x' ____________ -> 'x and y' |
print('{} and {}'.format(a,b)) |
|
a='first' b='second' print(____________.format(b, a)) |
print('{1} and {0}'.format(b,a)) |
|
What flags are used to indicate the str() and repr() representations? |
str = '{0!s}' repr = {0!r} |
|
What flag is used to use the ascii value of the repr() method? |
a = '{0!a}' |
|
How do you left-pad a string to a minimum of 10 spaces? |
'{:>10}'.format('test') |
|
How do you right-pad a string to a minimum of 10 spaces? |
'{:10}'.format('test') |
|
How do you centre-align a string in a 10 total character string? |
'{:^10}'.format('test) |
|
How do you pad with other characters (ex: '_')? |
'{:_>10}'.format('test') |
|
How do you truncate a long string? (ex. to 5 characters) |
'{:.5}'.format('alongstring') |
|
How do you truncate a string to 5 characters and right pad it to 10 characters? |
'{:10.5}'.format('alongstring') |
|
What are the flags for integers and floats? |
'{:d}' and '{:f}' |
|
How do you pad a number to width 4? |
'{:4d}'.format(42) |
|
How do you pad a float so it has 2 decimal places, total width 6, and pads with 0s? |
'{:06.2f}'.format('3.14159') |
|
How do you always show a +/- sign in front of a number? |
'{:+d}'.format(42) |
|
How do you insert a space to positive numbers to retain consistent spacing with negative signs? |
'{: d}'.format(42) |
|
How do you control the total number of spaces allotted for the '-' and the number? |
'{:=5d}'.format((- 23)) |
|
data = {'first': 'Hodor', 'last': 'Hodor!'} _______.format(____) -> Hodor Hodor! |
'{first} {last}'.format(data**) |
|
data = [4, 8, 15, 16, 23, 42] _____.format(____) -> 8 4 |
'{d[2]} {d[4]}'.format(d=data) |
|
class Plant(object): type = 'tree' _____.format(___) ->tree |
'{p.type}'.format(p=Plant()) |
|
from datetime import datetime d = datetime(2001, 2, 3, 4, 5) _______.format(d) -> 2001-02-03 04:05 |
'{%Y}-{%m}-{%d} {%H}:{%M}'.format(d) |
|
Given prec = 3, str = "Gibberish", and n =2.7182, use parameterized precision to output: -> Gib = 2.718 |
'{:.{prec}} = {:.{prec}f}'.format(str, n, prec) |
|
How do you define custom formats for objects passed to the format() method? |
modify the __format__ function |