summaryrefslogtreecommitdiffhomepage
path: root/python3.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'python3.html.markdown')
-rw-r--r--python3.html.markdown15
1 files changed, 9 insertions, 6 deletions
diff --git a/python3.html.markdown b/python3.html.markdown
index 02745117..6a2a7ccd 100644
--- a/python3.html.markdown
+++ b/python3.html.markdown
@@ -208,9 +208,9 @@ li[4] # Raises an IndexError
# You can look at ranges with slice syntax.
# (It's a closed/open range for you mathy types.)
li[1:3] # => [2, 4]
-# Omit the beginning
-li[2:] # => [4, 3]
# Omit the end
+li[2:] # => [4, 3]
+# Omit the beginning
li[:3] # => [1, 2, 4]
# Select every second entry
li[::2] # =>[1, 4]
@@ -724,13 +724,16 @@ if __name__ == '__main__':
# Call the static method
print(Human.grunt()) # => "*grunt*"
- print(i.grunt()) # => "*grunt*"
-
+
+ # Cannot call static method with instance of object
+ # because i.grunt() will automatically put "self" (the object i) as an argument
+ print(i.grunt()) # => TypeError: grunt() takes 0 positional arguments but 1 was given
+
# Update the property for this instance
i.age = 42
# Get the property
- i.say(i.age) # => 42
- j.say(j.age) # => 0
+ i.say(i.age) # => "Ian: 42"
+ j.say(j.age) # => "Joel: 0"
# Delete the property
del i.age
# i.age # => this would raise an AttributeError