1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-08 07:46:46 +02:00

Merge pull request #17 from mrshankly/patch-1

Corrected the last element of li in the lists explanation
This commit is contained in:
Adam Bard
2013-06-28 14:02:45 -07:00

View File

@@ -122,7 +122,7 @@ li.append(3) # li is now [1, 2, 4, 3] again.
# Access a list like you would any array # Access a list like you would any array
li[0] #=> 1 li[0] #=> 1
# Look at the last element # Look at the last element
li[-1] #=> 4 li[-1] #=> 3
# Looking out of bounds is an IndexError # Looking out of bounds is an IndexError
try: try:
@@ -145,7 +145,7 @@ del li[2] # li is now [1, 2, 3]
li + other_li #=> [1, 2, 3, 4, 5, 6] - Note: li and other_li is left alone li + other_li #=> [1, 2, 3, 4, 5, 6] - Note: li and other_li is left alone
# Concatenate lists with extend # Concatenate lists with extend
li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6] li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
# Check for existence in a list with in # Check for existence in a list with in
1 in li #=> True 1 in li #=> True
@@ -259,14 +259,14 @@ prints:
""" """
for animal in ["dog", "cat", "mouse"]: for animal in ["dog", "cat", "mouse"]:
# You can use % to interpolate formatted strings # You can use % to interpolate formatted strings
print "%s is a mammal" % animal print "%s is a mammal" % animal
""" """
While loops go until a condition is no longer met. While loops go until a condition is no longer met.
prints: prints:
0 0
1 1
2 2
3 3
""" """
x = 0 x = 0