Invent with Python Ch6

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is stored inside the <code>cave = '' </code> variable?

A blank string.

What happens if you try to change a global variable inside of your program?

Attempting to change the value in a global variable from the local scope will leave the global variable unchanged.

What is another name for scopes?

Namespaces

Does the assignment statement execute the code which is located in the def-block at the same time which it creates the function?

No, it only defines what code is executed when we call the function we defined later in the program.

Can local scope variables change global scope variables?

No.

Can variables in the local and global scope have the same name?

No. For example, if you had a variable named spam in the global scope but also modified a variable named spam in the local scope (say, with an assignment statement) then the name "spam" can only refer to the local scope variable.

What happens to the def statement once the return statement in the def-block is executed?

Once the return statement is executed, the program immediately jumps out of the def-block. (This is like how the break statement will make the program jump out of a while-block.) The program execution moves back to the line which had called the function.

What happens to parameters once a function ends?

Parameters are destroyed once the function ends.

What are parameters?

Parameters are local variables that get defined when a function is called.

What are variable names in between the parentheses of a function called?

Parameters.

What is another instance where programmers use the word define besides the def statement?

Programmers also say that they define variables when they create them with an assignment statement. The code spam = 42 defines the variable spam.

When does the 'return cave' statement execute?

The 'return cave' statement is executed when the variable 'cave' contains either a 1 or 2, and the <code>while cave != '1' and cave != '2':</code> statement evaluates to false.

Where is the 'return' keyword used?

The 'return' keyword is only used in def-blocks.

What is the code block after the def statement called?

The block after the def statement called the def-block.

When the function which has been created with the def statement is called, what will happen?

The code inside the def-block will be executed.

If you wanted to name a function BobbyTables() what would the line of code look like?

The code would look like this: <code>def BobbyTables():</code>

What does the def statement do?

The def statement means we are creating, or defining, a new function which we can call later in our program. After we define this function, we can call the function we created in the same way we call other functions. When we call this function, the code inside the def-block will be executed.

What is the scope inside a function called?

The scope inside of a function is called the local scope.

What is the scope outside of all functions called?

The scope outside of all functions is called the global scope.

The statement <code>while cave != '1' and cave != '2':</code> is true when the variable 'cave' is equal to what?

The statement <code>while cave != '1' and cave != '2':</code> is true when the variable 'cave' contains a blank string.

What happens to the values of our vairables inside our program once the program ends?

The values in our program's variables are forgotten after the program ends. Variables created inside the function are forgotten after the execution leaves the function.

There are four parts of a def statement, name them in the order they are called.

There is the def keyword, the function name, the parenthesis, and the colon. They look like this: <code>def BobbyTables():</code>

What is the difference between 'local scope' and 'global scope' variables?

Variables defined in the global scope can be read outside and inside functions, but can only be modified outside of all functions.

When the program's execution reaches the def statement, what does it do with the def-block code?

When the program's execution reaches a def statement, it skips down to the end of the def-block. It will jump back to the top of the def-block when the displayIntro() function is called.

Can you use the return function by itself?

Yes, you can also use the return keyword by itself just to break out of the def function, just like the break keyword will break out of a while loop.

Can you read global variables inside of your program?

Yes.


Conjuntos de estudio relacionados

Advanced Marketing Spring Semester Final Review

View Set

Chapter 1 - Cultural Anthropology

View Set

Chapter 17: Plate Tectonics Test

View Set

French Revolution, World Revolution

View Set

Chapter 13: The Nursing Role in Promoting Nutritional Health During Pregnancy

View Set