diff --git a/docs/1.0/.buildinfo b/docs/1.0/.buildinfo index 3eeb4cc080..6fb0019cb2 100644 --- a/docs/1.0/.buildinfo +++ b/docs/1.0/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 48324bcef729fa4a73edd2dc46b54931 +config: 36892e85cf892bc1dc3b073d36cc8085 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/1.0/Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-More-on-Commands.html b/docs/1.0/Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-More-on-Commands.html index f827553e53..2ccbeaa746 100644 --- a/docs/1.0/Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-More-on-Commands.html +++ b/docs/1.0/Howtos/Beginner-Tutorial/Part1/Beginner-Tutorial-More-on-Commands.html @@ -196,7 +196,7 @@ you are in a hurry. Time to modify target, *weapon = target.split(" ", 1) self.target = target.strip() if weapon: - self.weapon = weapon.strip() + self.weapon = weapon[0].strip() else: self.weapon = "" @@ -242,13 +242,11 @@ of this split is a list. Just how that list looks depends on the string
  • hit smaug sword gives ["smaug sword"]

  • hit smaug with sword gives ["smaug", "sword"]

  • -

    So we get a list of 1 or 2 elements. We assign it to two variables like this, target, *weapon = . That -asterisk in *weapon is a nifty trick - it will automatically become a list of 0 or more values. It sorts of -“soaks” up everything left over.

    +

    So we get a list of 1 or 2 elements. We assign it to two variables like this, target, *weapon = . That asterisk in *weapon is a nifty trick - it will automatically become a tuple of 0 or more values. It sorts of “soaks” up everything left over.

      -
    1. target becomes "smaug" and weapon becomes []

    2. -
    3. target becomes "smaug sword" and weapon becomes []

    4. -
    5. target becomes "smaug" and weapon becomes sword

    6. +
    7. target becomes "smaug" and weapon becomes () (an empty tuple)

    8. +
    9. target becomes "smaug sword" and weapon becomes ()

    10. +
    11. target becomes "smaug" and weapon becomes ("sword",) (this is a tuple with one element, the comma is required to indicate this).

  • Lines 16-17 - In this if condition we check if weapon is falsy (that is, the empty list). This can happen @@ -257,17 +255,13 @@ under two conditions (from the example above):

  • target is simply smaug

  • target is smaug sword

  • -

    To separate these cases we split target once again, this time by empty space " ". Again we store the -result back with target, *weapon =. The result will be one of the following:

    +

    To separate these cases we split target once again, this time by empty space " ". Again we store the result back with target, *weapon =. The result will be one of the following:

      -
    1. target remains smaug and weapon remains []

    2. -
    3. target becomes smaug and weapon becomes sword

    4. +
    5. target remains "smaug" and weapon remains []

    6. +
    7. target becomes "smaug" and weapon becomes ("sword",)

    -
  • Lines 18-22 - We now store target and weapon into self.target and self.weapon. We must do this in order -for these local variables to made available in func later. Note how we need to check so weapon is not falsy -before running strip() on it. This is because we know that if it’s falsy, it’s an empty list [] and lists -don’t have the .strip() method on them (so if we tried to use it, we’d get an error).

  • +
  • Lines 18-22 - We now store target and weapon into self.target and self.weapon. We must store on self in order for these local variables to become available in func later. Note that once we know that weapon exists, it must be a tuple (like ("sword",)), so we use weapon[0] to get the first element of that tuple (tuples and lists in Python are indexed from 0). The instruction weapon[0].strip() can be read as “get the first string stored in the tuple weapon and remove all extra whitespace on it with .strip()”. If we forgot the [0] here, we’d get an error since a tuple (unlike the string inside the tuple) does not have the .strip() method.

  • Now onto the func method. The main difference is we now have self.target and self.weapon available for convenient use.