diff options
Diffstat (limited to 'python.html.markdown')
| -rw-r--r-- | python.html.markdown | 17 | 
1 files changed, 11 insertions, 6 deletions
| diff --git a/python.html.markdown b/python.html.markdown index 7055689e..7d7e4baf 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -15,8 +15,8 @@ executable pseudocode.  Feedback would be highly appreciated! You can reach me at [@louiedinh](http://twitter.com/louiedinh) or louiedinh [at] [google's email service]  Note: This article applies to Python 2.7 specifically, but should be applicable -to Python 2.x. Python 2.7 is reachong end of life and will stop beeign maintained in 2020, -it is though recommended to start learnign Python with Python 3. +to Python 2.x. Python 2.7 is reaching end of life and will stop being maintained in 2020, +it is though recommended to start learning Python with Python 3.  For Python 3.x, take a look at the [Python 3 tutorial](http://learnxinyminutes.com/docs/python3/).  It is also possible to write Python code which is compatible with Python 2.7 and 3.x at the same time, @@ -123,8 +123,12 @@ not False  # => True  # A string can be treated like a list of characters  "This is a string"[0]  # => 'T' -# % can be used to format strings, like this: -"%s can be %s" % ("strings", "interpolated") +#String formatting with % +#Even though the % string operator will be deprecated on Python 3.1 and removed  +#later at some time, it may still be good to know how it works. +x = 'apple' +y = 'lemon' +z = "The items in the basket are %s and %s" % (x,y)  # A newer way to format strings is the format method.  # This method is the preferred way @@ -242,7 +246,7 @@ li.remove(2)  # Raises a ValueError as 2 is not in the list  li.insert(1, 2)  # li is now [1, 2, 3, 4, 5, 6] again  # Get the index of the first item found -li.index(2)  # => 3 +li.index(2)  # => 1  li.index(7)  # Raises a ValueError as 7 is not in the list  # Check for existence in a list with "in" @@ -265,8 +269,9 @@ tup[:2]   # => (1, 2)  # You can unpack tuples (or lists) into variables  a, b, c = (1, 2, 3)     # a is now 1, b is now 2 and c is now 3 +d, e, f = 4, 5, 6       # you can leave out the parentheses  # Tuples are created by default if you leave out the parentheses -d, e, f = 4, 5, 6 +g = 4, 5, 6             # => (4, 5, 6)  # Now look how easy it is to swap two values  e, d = d, e     # d is now 5 and e is now 4 | 
