summaryrefslogtreecommitdiffhomepage
path: root/python.html.markdown
diff options
context:
space:
mode:
authorGeoff Liu <g@geoffliu.me>2015-08-30 14:22:11 -0600
committerGeoff Liu <g@geoffliu.me>2015-08-30 14:22:11 -0600
commiteb7e58d5fc649ed2713c7685539bd5edcd9e8ade (patch)
tree72a9fe5106bed0735089b5c7a2b22540f7ebb3a7 /python.html.markdown
parent1d1def16a5d7925bb8f7fba7dc49182e33359e85 (diff)
parentb124fd58df56a5e1ee9925481fbde1f22ccfb386 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'python.html.markdown')
-rw-r--r--python.html.markdown11
1 files changed, 6 insertions, 5 deletions
diff --git a/python.html.markdown b/python.html.markdown
index ace3f794..88e0deb1 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -327,8 +327,8 @@ prints:
mouse is a mammal
"""
for animal in ["dog", "cat", "mouse"]:
- # You can use % to interpolate formatted strings
- print "%s is a mammal" % animal
+ # You can use {0} to interpolate formatted strings. (See above.)
+ print "{0} is a mammal".format(animal)
"""
"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
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
# Calling functions with parameters
@@ -497,7 +497,7 @@ class Human(object):
# An instance method. All methods take "self" as the first argument
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
# They are called with the calling class as the first argument
@@ -624,16 +624,17 @@ print say(say_please=True) # Can you buy me a beer? Please! I am poor :(
### Free Online
+* [Automate the Boring Stuff with Python](https://automatetheboringstuff.com)
* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
* [Dive Into Python](http://www.diveintopython.net/)
* [The Official Docs](http://docs.python.org/2.6/)
* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
* [Python Module of the Week](http://pymotw.com/2/)
* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
+* [First Steps With Python](https://realpython.com/learn/python-first-steps/)
### Dead Tree
* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20)
-