diff options
Diffstat (limited to 'python.html.markdown')
-rw-r--r-- | python.html.markdown | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/python.html.markdown b/python.html.markdown index a599f5d3..4cfecbbd 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -8,6 +8,8 @@ Python was created by Guido Van Rossum in the early 90's. It is now one of the m languages in existence. I fell in love with Python for it's syntactic clarity. It's basically 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. Look for another tour of Python 3 soon! @@ -32,11 +34,11 @@ to Python 2.x. Look for another tour of Python 3 soon! # Division is a bit tricky. It is integer division and floors the results # automatically. -11 / 4 #=> 2 +5 / 2 #=> 2 # To fix division we need to learn about floats. 2.0 # This is a float -5.0 / 2.0 #=> 2.5 ahhh...much better +11.0 / 4.0 #=> 2.75 ahhh...much better # Enforce precedence with parentheses (1 + 3) * 2 #=> 8 @@ -134,9 +136,9 @@ except IndexError: # (It's a closed/open range for you mathy types.) li[1:3] #=> [2, 4] # Omit the beginning -li[:3] #=> [1, 2, 4] -# Omit the end li[2:] #=> [4, 3] +# Omit the end +li[:3] #=> [1, 2, 4] # Remove arbitrary elements from a list with del del li[2] # li is now [1, 2, 3] @@ -167,7 +169,7 @@ tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6) tup[:2] #=> (1, 2) 2 in tup #=> True -# However, you can unpack tuples into variables +# You can unpack tuples into variables a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3 # Tuples are created by default if you leave out the parentheses d, e, f = 4, 5, 6 @@ -407,3 +409,7 @@ j.get_species() #=> "H. neanderthalensis" Human.grunt() #=> "*grunt*" ``` +## Further Reading + +Still up for more? Try [Learn Python The Hard Way](http://learnpythonthehardway.org/book/) + |