mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 15:51:41 +03:00
Merge pull request #1167 from MrMallIronmaker/patch-1
Changed %s formatting to {n} style.
This commit is contained in:
commit
cad5789e26
@ -327,8 +327,8 @@ prints:
|
|||||||
mouse is a mammal
|
mouse is a mammal
|
||||||
"""
|
"""
|
||||||
for animal in ["dog", "cat", "mouse"]:
|
for animal in ["dog", "cat", "mouse"]:
|
||||||
# You can use % to interpolate formatted strings
|
# You can use {0} to interpolate formatted strings. (See above.)
|
||||||
print "%s is a mammal" % animal
|
print "{0} is a mammal".format(animal)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
"range(number)" returns a list of numbers
|
"range(number)" returns a list of numbers
|
||||||
@ -387,7 +387,7 @@ else: # Optional clause to the try/except block. Must follow all except blocks
|
|||||||
|
|
||||||
# Use "def" to create new functions
|
# Use "def" to create new functions
|
||||||
def add(x, y):
|
def add(x, y):
|
||||||
print "x is %s and y is %s" % (x, y)
|
print "x is {0} and y is {1}".format(x, y)
|
||||||
return x + y # Return values with a return statement
|
return x + y # Return values with a return statement
|
||||||
|
|
||||||
# Calling functions with parameters
|
# Calling functions with parameters
|
||||||
@ -497,7 +497,7 @@ class Human(object):
|
|||||||
|
|
||||||
# An instance method. All methods take "self" as the first argument
|
# An instance method. All methods take "self" as the first argument
|
||||||
def say(self, msg):
|
def say(self, msg):
|
||||||
return "%s: %s" % (self.name, msg)
|
return "{0}: {1}".format(self.name, msg)
|
||||||
|
|
||||||
# A class method is shared among all instances
|
# A class method is shared among all instances
|
||||||
# They are called with the calling class as the first argument
|
# They are called with the calling class as the first argument
|
||||||
|
Loading…
Reference in New Issue
Block a user