Learn Python the Hard way ex25 - Want to check my understanding
<p>total noob here confused all to hell about something in "Learn Python the Hard Way." Apologies if this has been covered; I searched and could only find posts about not getting the desired results from the code.</p>

<p>My question relates to the interaction of two functions in <a href="https://learnpythonthehardway.org/book/ex25.html" rel="nofollow">exercise 25</a>:</p>

<pre><code>def break_words(stuff):
    words = stuff.split(' ')
    return words
</code></pre>

<p>and</p>

<pre><code>def sort_sentence(sentence):
    words = break_words(sentence)
    return sort_words(words)
</code></pre>

<p>So, near the end of the exercise Zed has you run this in the terminal:</p>

<pre><code>&gt;&gt;&gt; sorted_words = ex25.sort_sentence(sentence)
&gt;&gt;&gt; sorted_words
['All', 'come', âgoodâ, âthingsâ, âthoseâ, âtoâ, âwait.â, âwhoâ]
</code></pre>

<p>Now I assume the argument in 'sort_sentence' comes from the following, entered in the terminal at the start of the exercise:</p>

<pre><code>&gt;&gt;&gt; sentence = "All good things come to those who wait."
</code></pre>

<p>But although we now know the above is the argument for 'sort_sentence,' 'sort_sentence' can't complete without running 'break_words', with 'sentence' again as <em>its</em> argument. Here's where I get confused: The argument for 'break_words' is labeled 'stuff.' Does this matter? Can 'sentence' just be passed into 'break_words' from 'sorted_words' no matter what the argument for 'break_words' is labeled?</p>

<p>So assuming what I assumed - that the argument label doesn't matter - 'break_words' ought to run with 'sentence' as its argument and return 'words', which is the output of the function 'stuff.split' contained therein. This is where I get <em>really</em> confused - what does the 'words' returned from 'break_words' have to do with the variable 'words' defined as a part of 'sort_sentence'? I simply can't figure out how these functions work together. Thank you in advance for your help!</p>

<blockquote>
  <p>that the argument label doesn't matter</p>
</blockquote>

<p>It matters in the sense that it's used "locally" within the function definition.  Basically think of it as another local variable you define in the function definition but the values of the arguments are given to the function.</p>

<p>Keeping this in mind, your next question is easy to answer:</p>

<blockquote>
  <p>what does the 'words' returned from 'break_words' have to do with the
  variable 'words' defined as a part of 'sort_sentence'?</p>
</blockquote>

<p>Nothing.  As stated previously, <code>words</code> is a local variable of <code>sort_sentence</code> and so is basically trashed when you leave the function ("falls out of scope" is the lingo).  Of course, you can use <code>words</code> as the name of variables elsewhere, such as in another function definition, and that's what's happening here.</p>

python