mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 10:01:38 +00:00
Merge pull request #1077 from geoffliu/master
[Python3/en] Python3 doc cleanup
This commit is contained in:
commit
d26900150d
@ -186,7 +186,7 @@ li[2:] # => [4, 3]
|
||||
li[:3] # => [1, 2, 4]
|
||||
# Select every second entry
|
||||
li[::2] # =>[1, 4]
|
||||
# Revert the list
|
||||
# Return a reversed copy of the list
|
||||
li[::-1] # => [3, 4, 2, 1]
|
||||
# Use any combination of these to make advanced slices
|
||||
# li[start:end:step]
|
||||
@ -213,7 +213,7 @@ tup = (1, 2, 3)
|
||||
tup[0] # => 1
|
||||
tup[0] = 3 # Raises a TypeError
|
||||
|
||||
# You can do all those list thingies on tuples too
|
||||
# You can do most of the list operations on tuples too
|
||||
len(tup) # => 3
|
||||
tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6)
|
||||
tup[:2] # => (1, 2)
|
||||
@ -235,15 +235,15 @@ filled_dict = {"one": 1, "two": 2, "three": 3}
|
||||
# Look up values with []
|
||||
filled_dict["one"] # => 1
|
||||
|
||||
# Get all keys as a list with "keys()".
|
||||
# We need to wrap the call in list() because we are getting back an iterable. We'll talk about those later.
|
||||
# Note - Dictionary key ordering is not guaranteed.
|
||||
# Your results might not match this exactly.
|
||||
# Get all keys as an iterable with "keys()". We need to wrap the call in list()
|
||||
# to turn it into a list. We'll talk about those later. Note - Dictionary key
|
||||
# ordering is not guaranteed. Your results might not match this exactly.
|
||||
list(filled_dict.keys()) # => ["three", "two", "one"]
|
||||
|
||||
|
||||
# Get all values as a list with "values()". Once again we need to wrap it in list() to get it out of the iterable.
|
||||
# Note - Same as above regarding key ordering.
|
||||
# Get all values as an iterable with "values()". Once again we need to wrap it
|
||||
# in list() to get it out of the iterable. Note - Same as above regarding key
|
||||
# ordering.
|
||||
list(filled_dict.values()) # => [3, 2, 1]
|
||||
|
||||
|
||||
@ -328,7 +328,7 @@ for animal in ["dog", "cat", "mouse"]:
|
||||
print("{} is a mammal".format(animal))
|
||||
|
||||
"""
|
||||
"range(number)" returns a list of numbers
|
||||
"range(number)" returns an iterable of numbers
|
||||
from zero to the given number
|
||||
prints:
|
||||
0
|
||||
@ -340,7 +340,7 @@ for i in range(4):
|
||||
print(i)
|
||||
|
||||
"""
|
||||
"range(lower, upper)" returns a list of numbers
|
||||
"range(lower, upper)" returns an iterable of numbers
|
||||
from the lower number to the upper number
|
||||
prints:
|
||||
4
|
||||
|
Loading…
Reference in New Issue
Block a user