Skip to content

Commit f82fbc3

Browse files
committed
fix the tabs to spaces
1 parent 05020d9 commit f82fbc3

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

docs/readability/not_using_dict_keys_when_formatting_strings.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Here is an example of formatting the string with values from the person. This is
1717

1818
.. code:: python
1919
20-
person = {'first':'Tobin', 'age':20}
21-
print('{0} is {1} years old'.format(person['first'], person['age'])) # bad
20+
person = {'first':'Tobin', 'age':20}
21+
print('{0} is {1} years old'.format(person['first'], person['age'])) # bad
2222
23-
person = {'first':'Tobin', 'last': 'Brown', 'age':20}
24-
print('{0} {1} is {2} years old'.format(person['first'], person['last'], person['age'])) # bad
23+
person = {'first':'Tobin', 'last': 'Brown', 'age':20}
24+
print('{0} {1} is {2} years old'.format(person['first'], person['last'], person['age'])) # bad
2525
2626
2727
Best practice
@@ -31,7 +31,7 @@ By using the dictionary keys in the string we are formatting, the code is much m
3131

3232
.. code:: python
3333
34-
person = {'first':'Tobin', 'age':20}
34+
person = {'first':'Tobin', 'age':20}
3535
print('{first} is {age} years old'.format(**person))
3636
3737
person = {'first':'Tobin', 'last': 'Brown', 'age':20}
@@ -42,16 +42,16 @@ Going even further, the same result can be achieved with your own objects by usi
4242

4343
.. code:: python
4444
45-
class Person(object):
45+
class Person(object):
4646
47-
def __init__(self, first, last, age):
48-
self.first = first
49-
self.last = last
50-
self.age = age
47+
def __init__(self, first, last, age):
48+
self.first = first
49+
self.last = last
50+
self.age = age
5151
52-
def __str__(self):
53-
return '{first} {last} is {age} years old'.format(**self.__dict__)
52+
def __str__(self):
53+
return '{first} {last} is {age} years old'.format(**self.__dict__)
5454
5555
56-
person = Person('Tobin', 'Brown', 20)
57-
print(person)
56+
person = Person('Tobin', 'Brown', 20)
57+
print(person)

0 commit comments

Comments
 (0)