chapter3 Flashcards

1
Q
  1. Why are functions advantageous to have in your programs?
A

Functions reduce the need for duplicate code. This makes programs shorter,
easier to read, and easier to update.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. When does the code in a function execute: when the function is defined or when the function is called?
A
The code in a function executes when the function is called, not when the
function is defined.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What statement creates a function?
A

The def statement defines (that is, creates) a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What is the difference between a function and a function call?
A
A function consists of the def statement and the code in its def clause.
A function call is what moves the program execution into the function, and the
function call evaluates to the function’s return value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. How many global scopes are there in a Python program? How many local scopes?
A

There is one global scope, and a local scope is created whenever a function is
called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What happens to variables in a local scope when the function call returns?
A

When a function returns, the local scope is destroyed, and all the variables in it
are forgotten.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. What is a return value? Can a return value be part of an expression?
A
  1. A return value is the value that a function call — evaluates to—. Like any value, a
    return value can be used as part of an expression.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. If a function does not have a return statement, what is the return value of a call to that function?
A
  1. If there is no return statement for a function, its return value is None.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. How can you force a variable in a function to refer to the global variable?

o co w tym chodzi ????

A
  1. A global statement will force a variable in a function to refer to the global
    variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. What is the data type of None?
A
  1. The data type of None is NoneType.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. What does the import areallyourpetsnamederic statement do?
A
  1. That import statement imports a module named areallyourpetsnamederic.
    CHAPTER 4
    (This isn’t a real Python module, by the way.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. If you had a function named bacon() in a module named spam, how would you call it after importing spam?
A
  1. This function can be called with spam.bacon().
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. How can you prevent a program from crashing when it gets an error?
A
  1. Place the line of code that might cause an error in a try clause.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. What goes in the try clause? What goes in the except clause?
A
  1. The code that could potentially cause an error goes in the try clause.
    The code that executes if an error happens goes in the except clause.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly