summaryrefslogtreecommitdiffhomepage
path: root/python.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'python.html.markdown')
-rw-r--r--python.html.markdown16
1 files changed, 10 insertions, 6 deletions
diff --git a/python.html.markdown b/python.html.markdown
index 2b67ab83..467a179e 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -2,6 +2,7 @@
language: python
author: Louie Dinh
author_url: http://ldinh.ca
+filename: learnpython.py
---
Python was created by Guido Van Rossum in the early 90's. It is now one of the most popular
@@ -15,7 +16,7 @@ to Python 2.x. Look for another tour of Python 3 soon!
```python
# Single line comments start with a hash.
-""" Multiline strings can we written
+""" Multiline strings can be written
using three "'s, and are often used
as comments
"""
@@ -110,7 +111,7 @@ except NameError:
print "Raises a name error"
# if can be used as an expression
-some_var = a if a > b else b
+some_var = 1 if 1 > 2 else 2 # => 2
# If a is greater than b, then a is assigned to some_var.
# Otherwise b is assigned to some_var.
@@ -206,8 +207,11 @@ filled_dict.values() #=> [3, 2, 1]
"one" in filled_dict #=> True
1 in filled_dict #=> False
-# Trying to look up a non-existing key will raise a KeyError
-filled_dict["four"] #=> KeyError
+try:
+ # Trying to look up a non-existing key will raise a KeyError
+ filled_dict["four"] #=> KeyError
+except KeyError:
+ pass
# Use get method to avoid the KeyError
filled_dict.get("one") #=> 1
@@ -234,7 +238,7 @@ filled_set = {1, 2, 2, 3, 4} # => {1 2 3 4}
filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5}
# Do set intersection with &
-other_set = set{3, 4, 5, 6}
+other_set = {3, 4, 5, 6}
filled_set & other_set #=> {3, 4, 5}
# Do set union with |
@@ -336,7 +340,7 @@ def keyword_args(**kwargs):
keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
# You can do both at once, if you like
-def all_the_args(*args, **kwargs):
+def foo(*args, **kwargs):
print args
print kwargs
"""