WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/readability/not_using_dict_keys_when_formatting_strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Here is an example of formatting the string with values from the person. This is

person = {
'first': 'Tobin',
'age':20
'age': 20
}

print('{0} is {1} years old'.format(
Expand All @@ -33,7 +33,7 @@ Here is an example of formatting the string with values from the person. This is
person = {
'first': 'Tobin',
'last': 'Brown',
'age':20
'age': 20
}

# Bad: we have to change the replacement fields within
Expand All @@ -55,16 +55,16 @@ By using the dictionary keys in the string we are formatting, the code is much m

person = {
'first': 'Tobin',
'age':20
'age': 20
}

print('{first} is {age} years old'.format(**person))
# Output: Tobin is 20 years old

person = {
'first':'Tobin',
'first': 'Tobin',
'last': 'Brown',
'age':20
'age': 20
}
print('{first} {last} is {age} years old'.format(**person))
# Output: Tobin Brown is 20 years old
Expand Down