Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
Define a local variable in a function and attempt to print it outside the function. What do you expect to happen?
Think about where the variable is declared.
Create a script with both a local variable and a global variable. Demonstrate how changing the global variable affects the local variable (if at all).
Remember to define your global variable outside of any functions.
What is a local variable?
Think about where the variable is created.
True or False: A global variable is accessible only within the function it was defined.
Remember where global variables are defined.
Define a global variable in your script. Then write a function that takes an argument with the same name as the global variable. Discuss the outcome when both are used in computation.
Use print statements to understand which variable is being accessed.
Create a Python program with both local and global variables and demonstrate how changing the global variable within a function affects the output outside the function.
Look at how variables are accessed and modified within functions.
1 more question in this section. Enroll free to practise them all.
Enroll free