W13 Flashcards
What is the scope of Local variables?
Inside the function they are defined in.
What does a variable scope mean?
The parts of the program in which the variable is visible (accessed or modified).
Are parameter variables local or global?
Local
What type of errors will occur when using a variable out of its scope?
A compiler error
Can two different local variables have the same name and different values?
Yes
Variables defined outside of functions are considered as what type of variables?
Global variables
Global variables can be visible (accessed and modified) by what functions?
A global variable is visible to all functions that are defined after it.
How can you create or modify a global variable inside a function?
Using the keyword “global”. Otherwise, instead of accessing the global variable, a local variable will be created with the same global variable name
What are the Python collections?
Give an example
Collections are
containers that store data, such as Lists.
What operator do you use to access a list element?
The subscript operator [ ].
What operator do you use to create a list element?
The square brackets [ ].
What operator do you use to print, access or modify a part of a list?
The slice operator [ n1 : n2 ]
list[ : 6 ], what indexes will be printed?
from 0 to 5
list[ 6 : ], what indexes will be printed?
from 6 to last index
list[ 3 : 9 ], what indexes will be printed?
from 3 to 8