12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

B RAINB UILDERChapter Quiz1. What is the output of the following code, and why?>>> X = 'Spam'>>> def func( ):... print X...>>> func( )2. What is the output of this code, and why?>>> X = 'Spam'>>> def func( ):... X = 'NI!'...>>> func( )>>> print X3. What does this code print, and why?>>> X = 'Spam'>>> def func( ):... X = 'NI'... print X...>>> func( )>>> print X4. What output does this code produce; again, why?>>> X = 'Spam'>>> def func( ):... global X... X = 'NI'...>>> func( )>>> print X5. What about this code—what’s the output, and why?>>> X = 'Spam'>>> def func( ):... X = 'NI'... def nested( ):... print X... nested( )...>>> func( )>>> X6. One last time: what is the output of this, and why?>>> def func(a, b, c=3, d=4): print a, b, c, d...>>> func(1, *(5,6))7. Name three or four ways to retain state information in a <strong>Python</strong> function.8. Name three ways that functions can communicate results to a caller.342 | Chapter 16: Scopes and Arguments

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!