mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[python3/en] Clean up confusion between % and .format()
This commit is contained in:
parent
06087523c5
commit
0654a19b44
@ -292,7 +292,7 @@ prints:
|
||||
mouse is a mammal
|
||||
"""
|
||||
for animal in ["dog", "cat", "mouse"]:
|
||||
# You can use % to interpolate formatted strings
|
||||
# You can use format() to interpolate formatted strings
|
||||
print("{} is a mammal".format(animal))
|
||||
|
||||
"""
|
||||
@ -471,7 +471,7 @@ class Human(object):
|
||||
|
||||
# An instance method. All methods take "self" as the first argument
|
||||
def say(self, msg):
|
||||
return "{name}: {message}" % (name=self.name, message=msg)
|
||||
return "{name}: {message}".format(name=self.name, message=msg)
|
||||
|
||||
# A class method is shared among all instances
|
||||
# They are called with the calling class as the first argument
|
||||
|
Loading…
Reference in New Issue
Block a user